USE [RD_COMMON]
GO
/****** Object:  StoredProcedure [dbo].[RebuildAllIndexes]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RebuildAllIndexes]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[RebuildAllIndexes]
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
--USE RD_COMMON--Enter the name of the database you want to reindex 

DECLARE @TableName varchar(255) 

DECLARE TableCursor CURSOR FOR 
SELECT table_name FROM information_schema.tables 
WHERE table_type = ''base table'' 

OPEN TableCursor 

FETCH NEXT FROM TableCursor INTO @TableName 
WHILE @@FETCH_STATUS = 0 
BEGIN 
DBCC DBREINDEX(@TableName,'' '',90) 
FETCH NEXT FROM TableCursor INTO @TableName 
END 

CLOSE TableCursor 

DEALLOCATE TableCursor
END
' 
END
GO
/****** Object:  StoredProcedure [dbo].[USP_Star_Account]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_Star_Account]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[USP_Star_Account] AS
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--	Author:			c Copyright 2004 Andrews Consulting Group 
--	Procedure:		USP_Star_Account
--
--	Description:		User Stored Procedure - To be run after Star_Account Dimension Refresh
--				The intent is to SET the Account Parent for each defined account,
--				If the account has no parent, it is at the highest level, then AccountParent is blank.
--
--	Application:		Star_Account After Refresh Procedure
--
--
--Modification History
--
--Date			Modified By		Description
--01.01.2001 		<developer name>	<comments>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

DECLARE @BU CHAR(12)
DECLARE @STRING VARCHAR(4000)
 
DECLARE dbcheck_cursor CURSOR FOR
select distinct Businessunitcode from Star_Account

OPEN dbcheck_cursor
FETCH FROM dbcheck_cursor into @BU
 
WHILE @@FETCH_STATUS = 0
 
BEGIN
IF  EXISTS (SELECT * FROM sysobjects WHERE id = OBJECT_ID(N''[dbo].[accounttemp]'') AND type in (N''U''))
	BEGIN
		drop table dbo.Accounttemp
	END


Select Distinct sourceID,
Account,AccountDesc, AccountLevelOfDetail ,AccountParent,AccountParentDesc,
AccountLOD3,AccountLOD3Desc,AccountLOD4,AccountLOD4Desc,AccountLOD5,AccountLOD5Desc,
AccountLOD6,AccountLOD6Desc,AccountLOD7,AccountLOD7Desc,AccountLOD8,AccountLOD8Desc,
AccountLOD9,AccountLOD9Desc  into accounttemp
from Star_Account where 1=2  

Insert into accounttemp
select sourceid,account,AccountDesc, AccountLevelOfDetail,'''','''','''','''','''','''', 
'''','''','''','''','''','''','''','''','''','''' from Star_Account where Businessunitcode = @BU


/****** Object:  Index [IX_accounttemp_Account]    Script Date: 04/20/2009 15:26:31 ******/
CREATE NONCLUSTERED INDEX [IX_accounttemp_Account] ON [dbo].[accounttemp] 
(
	[Account] ASC,
	[sourceID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]


/****** Object:  Index [IX_accounttemp_AccountParent]    Script Date: 04/20/2009 15:27:01 ******/
CREATE NONCLUSTERED INDEX [IX_accounttemp_AccountParent] ON [dbo].[accounttemp] 
(
	[AccountParent] ASC,
	[sourceID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]


BEGIN TRAN
UPDATE AccountTemp
	SET 
		AccountTemp.AccountParent = ISNULL((SELECT MAX(Parent.Account) 
			FROM
				AccountTemp AS Parent
			WHERE
				Parent.Account < Child.Account AND
				Parent.SourceID = Child.SourceID AND
				Parent.AccountLevelOfDetail < Child.AccountLevelOfDetail),Child.Account)
	FROM 
		AccountTemp AS Child
COMMIT
----------------------------------------------------------------------------------------------------------------------------------------------------------------
--	SETs the Account Parent Description                                                                                                                     
----------------------------------------------------------------------------------------------------------------------------------------------------------------
BEGIN TRAN
UPDATE AccountTemp
	SET 
		AccountTemp.AccountParentDesc = ISNULL((SELECT Parent.AccountDesc
			FROM
				AccountTemp AS Parent
			WHERE
				Parent.SourceID = Child.SourceID AND
				Parent.Account = Child.AccountParent),space(1))
	FROM 
		AccountTemp AS Child
COMMIT


----------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------
UPDATE AccountTemp
	SET
		AccountTemp.AccountLOD3 = 
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN (
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3
					WHERE 
						L3.SourceID = Child.SourceID AND
						L3.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''3''),Child.Account))
				WHEN ''5'' THEN (
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3, 
						AccountTemp L4 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''4''),
					ISNULL((SELECT  						L3.Account
					FROM 
						AccountTemp L3
					WHERE 
						L3.SourceID = Child.SourceID AND
						L3.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''4''),Child.Account))) 				WHEN ''6'' THEN (
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4, 
						AccountTemp L5 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
 						L5.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''5''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3, 
						AccountTemp L4 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''5''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3
					WHERE 
						L3.Account = Child.AccountParent AND
						L3.SourceID = Child.SourceID AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''5''),Child.Account))))
				WHEN ''7'' THEN  (
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''6''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4, 
						AccountTemp L5 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''6''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3, 
						AccountTemp L4 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''6''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3
					WHERE 
						L3.SourceID = Child.SourceID AND
						L3.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''6''),Child.Account)))))
				WHEN ''8'' THEN  (
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''7''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''7''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4, 
						AccountTemp L5 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''7''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3, 
						AccountTemp L4 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''7''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3
					WHERE 
						L3.SourceID = Child.SourceID AND
						L3.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''7''),Child.Account))))))
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7,
						AccountTemp L8
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L8.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = L8.AccountParent AND
						L8.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7
					WHERE 						
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4, 
						AccountTemp L5 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3, 
						AccountTemp L4 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3
					WHERE 
						L3.SourceID = Child.SourceID AND
						L3.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),Child.Account)))))))
				END,
		AccountTemp.AccountLOD4 =
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN (
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4
					WHERE 
						L4.SourceID = Child.SourceID AND
						L4.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''4''),Child.Account))
				WHEN ''6'' THEN (
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4, 
						AccountTemp L5 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''5''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4
					WHERE 
						L4.SourceID = Child.SourceID AND
						L4.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''5''),Child.Account)))
				WHEN ''7'' THEN  (
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''6''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4, 
						AccountTemp L5 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''6''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4
					WHERE 
						L4.SourceID = Child.SourceID AND
						L4.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''6''),Child.Account))))
				WHEN ''8'' THEN  (
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''7''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''7''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4, 
						AccountTemp L5 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''7''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L4.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''7''),Child.Account)))))
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7,
						AccountTemp L8
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L8.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = L8.AccountParent AND
						L8.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''8''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''8''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''8''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4, 
						AccountTemp L5 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''8''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L4.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''8''),Child.Account))))))
				END,
		AccountTemp.AccountLOD5 =
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN Child.Account
				WHEN ''6'' THEN (
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L5.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''5''),Child.Account))
				WHEN ''7'' THEN  (
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''6''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5  					WHERE 
						L5.SourceID = Child.SourceID AND
						L5.Account = Child.AccountParent AND 						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''6''),Child.Account)))
				WHEN ''8'' THEN  (
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7
					WHERE
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND 
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''7''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''7''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L5.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''7''),Child.Account))))
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7,
						AccountTemp L8
					WHERE 
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L8.SourceID = Child.SourceID AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = L8.AccountParent AND
						L8.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''8''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7
					WHERE 
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''8''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''8''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L5.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''8''),Child.Account)))))
				END,
		AccountTemp.AccountLOD6 =
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN Child.Account
				WHEN ''6'' THEN Child.Account
				WHEN ''7'' THEN  (
					ISNULL((SELECT 
						L6.Account
					FROM 
						AccountTemp L6 
					WHERE 
						L6.SourceID = Child.SourceID AND
						L6.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''6''),Child.Account))
				WHEN ''8'' THEN  (
					ISNULL((SELECT  						L6.Account
					FROM 
						AccountTemp L6,
						AccountTemp L7
					WHERE 
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''7''),
					ISNULL((SELECT 
						L6.Account
					FROM 
						AccountTemp L6 
					WHERE 
						L6.SourceID = Child.SourceID AND
						L6.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''7''),Child.Account)))
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L6.Account
					FROM 
						AccountTemp L6,
						AccountTemp L7,
						AccountTemp L8
					WHERE 
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L8.SourceID = Child.SourceID AND 
						L6.Account = L7.AccountParent AND
						L7.Account = L8.AccountParent AND
						L8.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''8''),
					ISNULL((SELECT 
						L6.Account
					FROM 
						AccountTemp L6,
						AccountTemp L7
					WHERE 
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''8''),
					ISNULL((SELECT 
						L6.Account
					FROM 
						AccountTemp L6 
					WHERE 
						L6.SourceID = Child.SourceID AND
						L6.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''8''),Child.Account))))
				END,
		AccountTemp.AccountLOD7 =
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN Child.Account
				WHEN ''6'' THEN Child.Account
				WHEN ''7'' THEN Child.Account
				WHEN ''8'' THEN  (
					ISNULL((SELECT 
						L7.Account
					FROM 
						AccountTemp L7
					WHERE 
						L7.SourceID = Child.SourceID AND
						L7.Account = Child.AccountParent AND
						L7.AccountLevelOfDetail BETWEEN ''7'' AND ''7''),Child.Account))
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L7.Account
					FROM 
						AccountTemp L7,
						AccountTemp L8
					WHERE 
						L7.SourceID = Child.SourceID AND
						L8.SourceID = Child.SourceID AND
						L7.Account = L8.AccountParent AND
						L8.Account = Child.AccountParent AND
						L7.AccountLevelOfDetail BETWEEN ''7'' AND ''8''),
					ISNULL((SELECT 
						L7.Account
					FROM 
						AccountTemp L7
					WHERE 
						L7.SourceID = Child.SourceID AND
						L7.Account = Child.AccountParent AND
						L7.AccountLevelOfDetail BETWEEN ''7'' AND ''8''),Child.Account)))
				END,
		AccountTemp.AccountLOD8 = 
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN Child.Account
				WHEN ''6'' THEN Child.Account
				WHEN ''7'' THEN Child.Account
				WHEN ''8'' THEN Child.Account
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L8.Account
					FROM 
						AccountTemp L8
					WHERE 
						L8.SourceID = Child.SourceID AND
						L8.Account = Child.AccountParent AND
						L8.AccountLevelOfDetail BETWEEN ''8'' AND ''8''),Child.Account))
				END,
		AccountTemp.AccountLOD9 =
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN Child.Account
				WHEN ''6'' THEN Child.Account
				WHEN ''7'' THEN Child.Account
				WHEN ''8'' THEN Child.Account
				WHEN ''9'' THEN Child.Account
				END
	FROM 
		AccountTemp AS Child




----------------------------------------------------------------------------------------------------------------------------------------------------------------
-- UPDATE Level of Detail Descriptions LOD 3-9 
----------------------------------------------------------------------------------------------------------------------------------------------------------------


UPDATE 
AccountTemp
	SET 
		AccountLOD3Desc = Acc.AccountDesc
	FROM 
		AccountTemp  INNER JOIN 
		AccountTemp Acc ON
				(AccountTemp.AccountLOD3 = Acc.Account) AND 
				AccountTemp.SourceID = Acc.SourceID
UPDATE 
AccountTemp
	SET 
		AccountLOD4Desc = Acc.AccountDesc
	FROM  		AccountTemp  INNER JOIN 
		AccountTemp Acc ON
				(AccountTemp.AccountLOD4 = Acc.Account) AND 
				AccountTemp.SourceID = Acc.SourceID

UPDATE 
AccountTemp
	SET 
		AccountLOD5Desc = Acc.AccountDesc
	FROM 
		AccountTemp  INNER JOIN 
		AccountTemp Acc ON
				(AccountTemp.AccountLOD5 = Acc.Account) AND 
				AccountTemp.SourceID = Acc.SourceID

UPDATE 
AccountTemp
	SET 
		AccountLOD6Desc = Acc.AccountDesc
	FROM 
		AccountTemp  INNER JOIN 
		AccountTemp Acc ON
				(AccountTemp.AccountLOD6 = Acc.Account) AND 
				AccountTemp.SourceID = Acc.SourceID

UPDATE 
AccountTemp
	SET 
		AccountLOD7Desc = Acc.AccountDesc
	FROM 
		AccountTemp  INNER JOIN 
		AccountTemp Acc ON
				(AccountTemp.AccountLOD7 = Acc.Account) AND 
				AccountTemp.SourceID = Acc.SourceID

UPDATE 
AccountTemp
	SET 
		AccountLOD8Desc = Acc.AccountDesc
	FROM 
		AccountTemp  INNER JOIN 
		AccountTemp Acc ON
				(AccountTemp.AccountLOD8 = Acc.Account) AND 
				AccountTemp.SourceID = Acc.SourceID

UPDATE 
AccountTemp
	SET 
		AccountLOD9Desc = Acc.AccountDesc
	FROM 
		AccountTemp  INNER JOIN 
		AccountTemp Acc ON
				(AccountTemp.AccountLOD9 = Acc.Account) AND 
				AccountTemp.SourceID = Acc.SourceID


Update Star_Account 
set		
AccountParent =A.AccountParent,
AccountParentDesc=a.AccountParentDesc,
AccountLOD3=A.AccountLOD3,
AccountLOD3Desc=A.AccountLOD3Desc,
AccountLOD4=A.AccountLOD4,
AccountLOD4Desc=A.AccountLOD4Desc,
AccountLOD5=A.AccountLOD5,
AccountLOD5Desc=A.AccountLOD5Desc,
AccountLOD6=A.AccountLOD6,
AccountLOD6Desc=A.AccountLOD6Desc,
AccountLOD7=A.AccountLOD7,
AccountLOD7Desc=A.AccountLOD7Desc,
AccountLOD8=A.AccountLOD8,
AccountLOD8Desc=A.AccountLOD8Desc,
AccountLOD9=A.AccountLOD9,
AccountLOD9Desc=A.AccountLOD9Desc
from Star_Account g 
inner join AccountTemp a on (G.Account = a.account) 
Where G.BusinessUnitCode = @BU

FETCH NEXT FROM dbcheck_cursor INTO @BU

drop table Accounttemp
END

CLOSE dbcheck_cursor
DEALLOCATE dbcheck_cursor
' 
END
GO
/****** Object:  StoredProcedure [dbo].[USP_Star_Account_BU]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_Star_Account_BU]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[USP_Star_Account_BU]  @IBU char(12) AS
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--	Author:			c Copyright 2004 Andrews Consulting Group 
--	Procedure:		USP_Star_Account
--
--	Description:		User Stored Procedure - To be run after Star_Account Dimension Refresh
--				The intent is to SET the Account Parent for each defined account,
--				If the account has no parent, it is at the highest level, then AccountParent is blank.
--
--	Application:		Star_Account After Refresh Procedure
--
--
--Modification History
--
--Date			Modified By		Description
--01.01.2001 		<developer name>	<comments>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

DECLARE @BU CHAR(12)
DECLARE @STRING VARCHAR(4000)
 
DECLARE dbcheck_cursor CURSOR FOR
select distinct Businessunitcode from Star_Account where Businessunitcode = @IBU

OPEN dbcheck_cursor
FETCH FROM dbcheck_cursor into @BU
 
WHILE @@FETCH_STATUS = 0
 
BEGIN
IF  EXISTS (SELECT * FROM sysobjects WHERE id = OBJECT_ID(N''[dbo].[accounttemp]'') AND type in (N''U''))
	BEGIN
		drop table dbo.Accounttemp
	END


Select Distinct sourceID,
Account,AccountDesc, AccountLevelOfDetail ,AccountParent,AccountParentDesc,
AccountLOD3,AccountLOD3Desc,AccountLOD4,AccountLOD4Desc,AccountLOD5,AccountLOD5Desc,
AccountLOD6,AccountLOD6Desc,AccountLOD7,AccountLOD7Desc,AccountLOD8,AccountLOD8Desc,
AccountLOD9,AccountLOD9Desc  into accounttemp
from Star_Account where 1=2  

Insert into accounttemp
select sourceid,account,AccountDesc, AccountLevelOfDetail,'''','''','''','''','''','''', 
'''','''','''','''','''','''','''','''','''','''' from Star_Account where Businessunitcode = @BU

ALTER TABLE [dbo].[AccountTemp] ADD  CONSTRAINT [PK_Star_AccountTemp] PRIMARY KEY CLUSTERED 
(
	Account ASC,
	[SourceID] ASC
)

BEGIN TRAN
UPDATE AccountTemp
	SET 
		AccountTemp.AccountParent = ISNULL((SELECT MAX(Parent.Account) 
			FROM
				AccountTemp AS Parent
			WHERE
				Parent.Account < Child.Account AND
				Parent.SourceID = Child.SourceID AND
				Parent.AccountLevelOfDetail < Child.AccountLevelOfDetail),Child.Account)
	FROM 
		AccountTemp AS Child
COMMIT
----------------------------------------------------------------------------------------------------------------------------------------------------------------
--	SETs the Account Parent Description                                                                                                                     
----------------------------------------------------------------------------------------------------------------------------------------------------------------

BEGIN TRAN
UPDATE AccountTemp
	SET 
		AccountTemp.AccountParentDesc = ISNULL((SELECT Parent.AccountDesc
			FROM
				AccountTemp AS Parent
			WHERE
				Parent.SourceID = Child.SourceID AND
				Parent.Account = Child.AccountParent),space(1))
	FROM 
		AccountTemp AS Child
COMMIT


----------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------
UPDATE AccountTemp
	SET
		AccountTemp.AccountLOD3 = 
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN (
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3
					WHERE 
						L3.SourceID = Child.SourceID AND
						L3.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''3''),Child.Account))
				WHEN ''5'' THEN (
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3, 
						AccountTemp L4 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''4''),
					ISNULL((SELECT  						L3.Account
					FROM 
						AccountTemp L3
					WHERE 
						L3.SourceID = Child.SourceID AND
						L3.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''4''),Child.Account))) 				WHEN ''6'' THEN (
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4, 
						AccountTemp L5 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
 						L5.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''5''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3, 
						AccountTemp L4 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''5''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3
					WHERE 
						L3.Account = Child.AccountParent AND
						L3.SourceID = Child.SourceID AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''5''),Child.Account))))
				WHEN ''7'' THEN  (
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''6''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4, 
						AccountTemp L5 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''6''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3, 
						AccountTemp L4 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''6''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3
					WHERE 
						L3.SourceID = Child.SourceID AND
						L3.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''6''),Child.Account)))))
				WHEN ''8'' THEN  (
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND 						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''7''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''7''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4, 
						AccountTemp L5 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''7''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3, 
						AccountTemp L4 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''7''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3
					WHERE 
						L3.SourceID = Child.SourceID AND
						L3.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''7''),Child.Account))))))
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7,
						AccountTemp L8
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L8.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = L8.AccountParent AND
						L8.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7
					WHERE 						
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3,
						AccountTemp L4, 
						AccountTemp L5 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3, 
						AccountTemp L4 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						AccountTemp L3
					WHERE 
						L3.SourceID = Child.SourceID AND
						L3.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),Child.Account)))))))
				END,
		AccountTemp.AccountLOD4 =
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN (
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4
					WHERE 
						L4.SourceID = Child.SourceID AND
						L4.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''4''),Child.Account))
				WHEN ''6'' THEN (
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4, 
						AccountTemp L5 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''5''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4
					WHERE 
						L4.SourceID = Child.SourceID AND
						L4.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''5''),Child.Account)))
				WHEN ''7'' THEN  (
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''6''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4, 
						AccountTemp L5 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''6''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4
					WHERE 
						L4.SourceID = Child.SourceID AND
						L4.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''6''),Child.Account))))
				WHEN ''8'' THEN  (
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''7''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''7''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4, 
						AccountTemp L5 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''7''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L4.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''7''),Child.Account)))))
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7,
						AccountTemp L8
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L8.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = L8.AccountParent AND
						L8.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''8''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''8''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4,
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''8''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4, 
						AccountTemp L5 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''8''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						AccountTemp L4 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L4.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''8''),Child.Account))))))
				END,
		AccountTemp.AccountLOD5 =
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN Child.Account
				WHEN ''6'' THEN (
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L5.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''5''),Child.Account))
				WHEN ''7'' THEN  (
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''6''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5  					WHERE 
						L5.SourceID = Child.SourceID AND
						L5.Account = Child.AccountParent AND 						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''6''),Child.Account)))
				WHEN ''8'' THEN  (
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7
					WHERE
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND 
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''7''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''7''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L5.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''7''),Child.Account))))
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7,
						AccountTemp L8
					WHERE 
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L8.SourceID = Child.SourceID AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = L8.AccountParent AND
						L8.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''8''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5, 
						AccountTemp L6,
						AccountTemp L7
					WHERE 
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''8''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5, 
						AccountTemp L6 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''8''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						AccountTemp L5 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L5.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''8''),Child.Account)))))
				END,
		AccountTemp.AccountLOD6 =
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN Child.Account
				WHEN ''6'' THEN Child.Account
				WHEN ''7'' THEN  (
					ISNULL((SELECT 
						L6.Account
					FROM 
						AccountTemp L6 
					WHERE 
						L6.SourceID = Child.SourceID AND
						L6.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''6''),Child.Account))
				WHEN ''8'' THEN  (
					ISNULL((SELECT  						L6.Account
					FROM 
						AccountTemp L6,
						AccountTemp L7
					WHERE 
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''7''),
					ISNULL((SELECT 
						L6.Account
					FROM 
						AccountTemp L6 
					WHERE 
						L6.SourceID = Child.SourceID AND
						L6.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''7''),Child.Account)))
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L6.Account
					FROM 
						AccountTemp L6,
						AccountTemp L7,
						AccountTemp L8
					WHERE 
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L8.SourceID = Child.SourceID AND 
						L6.Account = L7.AccountParent AND
						L7.Account = L8.AccountParent AND
						L8.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''8''),
					ISNULL((SELECT 
						L6.Account
					FROM 
						AccountTemp L6,
						AccountTemp L7
					WHERE 
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''8''),
					ISNULL((SELECT 
						L6.Account
					FROM 
						AccountTemp L6 
					WHERE 
						L6.SourceID = Child.SourceID AND
						L6.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''8''),Child.Account))))
				END,
		AccountTemp.AccountLOD7 =
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN Child.Account
				WHEN ''6'' THEN Child.Account
				WHEN ''7'' THEN Child.Account
				WHEN ''8'' THEN  (
					ISNULL((SELECT 
						L7.Account
					FROM 
						AccountTemp L7
					WHERE 
						L7.SourceID = Child.SourceID AND
						L7.Account = Child.AccountParent AND
						L7.AccountLevelOfDetail BETWEEN ''7'' AND ''7''),Child.Account))
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L7.Account
					FROM 
						AccountTemp L7,
						AccountTemp L8
					WHERE 
						L7.SourceID = Child.SourceID AND
						L8.SourceID = Child.SourceID AND
						L7.Account = L8.AccountParent AND
						L8.Account = Child.AccountParent AND
						L7.AccountLevelOfDetail BETWEEN ''7'' AND ''8''),
					ISNULL((SELECT 
						L7.Account
					FROM 
						AccountTemp L7
					WHERE 
						L7.SourceID = Child.SourceID AND
						L7.Account = Child.AccountParent AND
						L7.AccountLevelOfDetail BETWEEN ''7'' AND ''8''),Child.Account)))
				END,
		AccountTemp.AccountLOD8 = 
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN Child.Account
				WHEN ''6'' THEN Child.Account
				WHEN ''7'' THEN Child.Account
				WHEN ''8'' THEN Child.Account
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L8.Account
					FROM 
						AccountTemp L8
					WHERE 
						L8.SourceID = Child.SourceID AND
						L8.Account = Child.AccountParent AND
						L8.AccountLevelOfDetail BETWEEN ''8'' AND ''8''),Child.Account))
				END,
		AccountTemp.AccountLOD9 =
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN Child.Account
				WHEN ''6'' THEN Child.Account
				WHEN ''7'' THEN Child.Account
				WHEN ''8'' THEN Child.Account
				WHEN ''9'' THEN Child.Account
				END
	FROM 
		AccountTemp AS Child




----------------------------------------------------------------------------------------------------------------------------------------------------------------
-- UPDATE Level of Detail Descriptions LOD 3-9 
----------------------------------------------------------------------------------------------------------------------------------------------------------------


UPDATE 
AccountTemp
	SET 
		AccountLOD3Desc = Acc.AccountDesc
	FROM 
		AccountTemp  INNER JOIN 
		AccountTemp Acc ON
				(AccountTemp.AccountLOD3 = Acc.Account) AND 
				AccountTemp.SourceID = Acc.SourceID
UPDATE 
AccountTemp
	SET 
		AccountLOD4Desc = Acc.AccountDesc
	FROM  		AccountTemp  INNER JOIN 
		AccountTemp Acc ON
				(AccountTemp.AccountLOD4 = Acc.Account) AND 
				AccountTemp.SourceID = Acc.SourceID

UPDATE 
AccountTemp
	SET 
		AccountLOD5Desc = Acc.AccountDesc
	FROM 
		AccountTemp  INNER JOIN 
		AccountTemp Acc ON
				(AccountTemp.AccountLOD5 = Acc.Account) AND 
				AccountTemp.SourceID = Acc.SourceID

UPDATE 
AccountTemp
	SET 
		AccountLOD6Desc = Acc.AccountDesc
	FROM 
		AccountTemp  INNER JOIN 
		AccountTemp Acc ON
				(AccountTemp.AccountLOD6 = Acc.Account) AND 
				AccountTemp.SourceID = Acc.SourceID

UPDATE 
AccountTemp
	SET 
		AccountLOD7Desc = Acc.AccountDesc
	FROM 
		AccountTemp  INNER JOIN 
		AccountTemp Acc ON
				(AccountTemp.AccountLOD7 = Acc.Account) AND 
				AccountTemp.SourceID = Acc.SourceID

UPDATE 
AccountTemp
	SET 
		AccountLOD8Desc = Acc.AccountDesc
	FROM 
		AccountTemp  INNER JOIN 
		AccountTemp Acc ON
				(AccountTemp.AccountLOD8 = Acc.Account) AND 
				AccountTemp.SourceID = Acc.SourceID

UPDATE 
AccountTemp
	SET 
		AccountLOD9Desc = Acc.AccountDesc
	FROM 
		AccountTemp  INNER JOIN 
		AccountTemp Acc ON
				(AccountTemp.AccountLOD9 = Acc.Account) AND 
				AccountTemp.SourceID = Acc.SourceID 


Update Star_Account 
set		
AccountParent =A.AccountParent,
AccountParentDesc=a.AccountParentDesc,
AccountLOD3=A.AccountLOD3,
AccountLOD3Desc=A.AccountLOD3Desc,
AccountLOD4=A.AccountLOD4,
AccountLOD4Desc=A.AccountLOD4Desc,
AccountLOD5=A.AccountLOD5,
AccountLOD5Desc=A.AccountLOD5Desc,
AccountLOD6=A.AccountLOD6,
AccountLOD6Desc=A.AccountLOD6Desc,
AccountLOD7=A.AccountLOD7,
AccountLOD7Desc=A.AccountLOD7Desc,
AccountLOD8=A.AccountLOD8,
AccountLOD8Desc=A.AccountLOD8Desc,
AccountLOD9=A.AccountLOD9,
AccountLOD9Desc=A.AccountLOD9Desc
from Star_Account g 
inner join AccountTemp a on (G.Account = a.account) 
Where G.BusinessUnitCode = @BU

FETCH NEXT FROM dbcheck_cursor INTO @BU

drop table Accounttemp
END

CLOSE dbcheck_cursor
DEALLOCATE dbcheck_cursor
' 
END
GO
/****** Object:  StoredProcedure [dbo].[USP_Star_Account_Model]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_Star_Account_Model]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'Create          PROCEDURE [dbo].[USP_Star_Account_Model] AS
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--	Author:			c Copyright 2004 Andrews Consulting Group 
--	Procedure:		USP_Star_Account_Model
--
--	Description:		User Stored Procedure - To be run after Star_Account_Model Dimension Refresh
--				The intent is to SET the Account Parent for each defined account,
--				If the account has no parent, it is at the highest level, then AccountParent is blank.
--
--	Application:		Star_Account_Model After Refresh Procedure
--
--
--Modification History
--
--Date			Modified By		Description
--01.01.2001 		<developer name>	<comments>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BEGIN TRAN
UPDATE RD_Common.dbo.Star_Account_Model
	SET 
		RD_Common.dbo.Star_Account_Model.AccountParent = ISNULL((SELECT MAX(Parent.Account) 
			FROM
				RD_Common.dbo.Star_Account_Model AS Parent
			WHERE
				Parent.Account < Child.Account AND
				Parent.SourceID = Child.SourceID AND
				Parent.AccountLevelOfDetail < Child.AccountLevelOfDetail),Child.Account)
	FROM 
		RD_Common.dbo.Star_Account_Model AS Child
COMMIT
----------------------------------------------------------------------------------------------------------------------------------------------------------------
--	SETs the Account Parent Description                                                                                                                     
----------------------------------------------------------------------------------------------------------------------------------------------------------------
BEGIN TRAN
UPDATE RD_Common.dbo.Star_Account_Model
	SET 
		RD_Common.dbo.Star_Account_Model.AccountParentDesc = ISNULL((SELECT Parent.AccountDesc
			FROM
				RD_Common.dbo.Star_Account_Model AS Parent
			WHERE
				Parent.SourceID = Child.SourceID AND
				Parent.Account = Child.AccountParent),space(1))
	FROM 
		RD_Common.dbo.Star_Account_Model AS Child
COMMIT


----------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------
UPDATE RD_Common.dbo.Star_Account_Model
	SET
		RD_Common.dbo.Star_Account_Model.AccountLOD3 = 
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN (
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3
					WHERE 
						L3.SourceID = Child.SourceID AND
						L3.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''3''),Child.Account))
				WHEN ''5'' THEN (
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3, 
						RD_Common.dbo.Star_Account_Model L4 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''4''),
					ISNULL((SELECT  						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3
					WHERE 
						L3.SourceID = Child.SourceID AND
						L3.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''4''),Child.Account))) 				WHEN ''6'' THEN (
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3,
						RD_Common.dbo.Star_Account_Model L4, 
						RD_Common.dbo.Star_Account_Model L5 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
 						L5.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''5''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3, 
						RD_Common.dbo.Star_Account_Model L4 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''5''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3
					WHERE 
						L3.Account = Child.AccountParent AND
						L3.SourceID = Child.SourceID AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''5''),Child.Account))))
				WHEN ''7'' THEN  (
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3,
						RD_Common.dbo.Star_Account_Model L4,
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''6''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3,
						RD_Common.dbo.Star_Account_Model L4, 
						RD_Common.dbo.Star_Account_Model L5 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''6''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3, 
						RD_Common.dbo.Star_Account_Model L4 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''6''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3
					WHERE 
						L3.SourceID = Child.SourceID AND
						L3.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''6''),Child.Account)))))
				WHEN ''8'' THEN  (
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3,
						RD_Common.dbo.Star_Account_Model L4,
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6,
						RD_Common.dbo.Star_Account_Model L7
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''7''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3,
						RD_Common.dbo.Star_Account_Model L4,
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''7''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3,
						RD_Common.dbo.Star_Account_Model L4, 
						RD_Common.dbo.Star_Account_Model L5 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''7''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3, 
						RD_Common.dbo.Star_Account_Model L4 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''7''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3
					WHERE 
						L3.SourceID = Child.SourceID AND
						L3.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''7''),Child.Account))))))
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3,
						RD_Common.dbo.Star_Account_Model L4,
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6,
						RD_Common.dbo.Star_Account_Model L7,
						RD_Common.dbo.Star_Account_Model L8
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L8.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = L8.AccountParent AND
						L8.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3,
						RD_Common.dbo.Star_Account_Model L4,
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6,
						RD_Common.dbo.Star_Account_Model L7
					WHERE 						
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3,
						RD_Common.dbo.Star_Account_Model L4,
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3,
						RD_Common.dbo.Star_Account_Model L4, 
						RD_Common.dbo.Star_Account_Model L5 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3, 
						RD_Common.dbo.Star_Account_Model L4 
					WHERE 
						L3.SourceID = Child.SourceID AND
						L4.SourceID = Child.SourceID AND
						L3.Account = L4.AccountParent AND
						L4.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),
					ISNULL((SELECT 
						L3.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L3
					WHERE 
						L3.SourceID = Child.SourceID AND
						L3.Account = Child.AccountParent AND
						L3.AccountLevelOfDetail BETWEEN ''3'' AND ''8''),Child.Account)))))))
				END,
		RD_Common.dbo.Star_Account_Model.AccountLOD4 =
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN (
					ISNULL((SELECT 
						L4.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L4
					WHERE 
						L4.SourceID = Child.SourceID AND
						L4.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''4''),Child.Account))
				WHEN ''6'' THEN (
					ISNULL((SELECT 
						L4.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L4, 
						RD_Common.dbo.Star_Account_Model L5 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''5''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L4
					WHERE 
						L4.SourceID = Child.SourceID AND
						L4.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''5''),Child.Account)))
				WHEN ''7'' THEN  (
					ISNULL((SELECT 
						L4.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L4,
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''6''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L4, 
						RD_Common.dbo.Star_Account_Model L5 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''6''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L4
					WHERE 
						L4.SourceID = Child.SourceID AND
						L4.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''6''),Child.Account))))
				WHEN ''8'' THEN  (
					ISNULL((SELECT 
						L4.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L4,
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6,
						RD_Common.dbo.Star_Account_Model L7
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''7''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L4,
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''7''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L4, 
						RD_Common.dbo.Star_Account_Model L5 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''7''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L4 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L4.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''7''),Child.Account)))))
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L4.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L4,
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6,
						RD_Common.dbo.Star_Account_Model L7,
						RD_Common.dbo.Star_Account_Model L8
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L8.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = L8.AccountParent AND
						L8.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''8''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L4,
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6,
						RD_Common.dbo.Star_Account_Model L7
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''8''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L4,
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''8''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L4, 
						RD_Common.dbo.Star_Account_Model L5 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L5.SourceID = Child.SourceID AND
						L4.Account = L5.AccountParent AND
						L5.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''8''),
					ISNULL((SELECT 
						L4.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L4 
					WHERE 
						L4.SourceID = Child.SourceID AND
						L4.Account = Child.AccountParent AND
						L4.AccountLevelOfDetail BETWEEN ''4'' AND ''8''),Child.Account))))))
				END,
		RD_Common.dbo.Star_Account_Model.AccountLOD5 =
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN Child.Account
				WHEN ''6'' THEN (
					ISNULL((SELECT 
						L5.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L5 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L5.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''5''),Child.Account))
				WHEN ''7'' THEN  (
					ISNULL((SELECT 
						L5.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''6''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L5  					WHERE 
						L5.SourceID = Child.SourceID AND
						L5.Account = Child.AccountParent AND 						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''6''),Child.Account)))
				WHEN ''8'' THEN  (
					ISNULL((SELECT 
						L5.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6,
						RD_Common.dbo.Star_Account_Model L7
					WHERE
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND 
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''7''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''7''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L5 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L5.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''7''),Child.Account))))
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L5.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6,
						RD_Common.dbo.Star_Account_Model L7,
						RD_Common.dbo.Star_Account_Model L8
					WHERE 
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L8.SourceID = Child.SourceID AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = L8.AccountParent AND
						L8.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''8''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6,
						RD_Common.dbo.Star_Account_Model L7
					WHERE 
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L5.Account = L6.AccountParent AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''8''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L5, 
						RD_Common.dbo.Star_Account_Model L6 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L6.SourceID = Child.SourceID AND
						L5.Account = L6.AccountParent AND
						L6.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''8''),
					ISNULL((SELECT 
						L5.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L5 
					WHERE 
						L5.SourceID = Child.SourceID AND
						L5.Account = Child.AccountParent AND
						L5.AccountLevelOfDetail BETWEEN ''5'' AND ''8''),Child.Account)))))
				END,
		RD_Common.dbo.Star_Account_Model.AccountLOD6 =
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN Child.Account
				WHEN ''6'' THEN Child.Account
				WHEN ''7'' THEN  (
					ISNULL((SELECT 
						L6.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L6 
					WHERE 
						L6.SourceID = Child.SourceID AND
						L6.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''6''),Child.Account))
				WHEN ''8'' THEN  (
					ISNULL((SELECT  						L6.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L6,
						RD_Common.dbo.Star_Account_Model L7
					WHERE 
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''7''),
					ISNULL((SELECT 
						L6.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L6 
					WHERE 
						L6.SourceID = Child.SourceID AND
						L6.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''7''),Child.Account)))
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L6.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L6,
						RD_Common.dbo.Star_Account_Model L7,
						RD_Common.dbo.Star_Account_Model L8
					WHERE 
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L8.SourceID = Child.SourceID AND 
						L6.Account = L7.AccountParent AND
						L7.Account = L8.AccountParent AND
						L8.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''8''),
					ISNULL((SELECT 
						L6.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L6,
						RD_Common.dbo.Star_Account_Model L7
					WHERE 
						L6.SourceID = Child.SourceID AND
						L7.SourceID = Child.SourceID AND
						L6.Account = L7.AccountParent AND
						L7.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''8''),
					ISNULL((SELECT 
						L6.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L6 
					WHERE 
						L6.SourceID = Child.SourceID AND
						L6.Account = Child.AccountParent AND
						L6.AccountLevelOfDetail BETWEEN ''6'' AND ''8''),Child.Account))))
				END,
		RD_Common.dbo.Star_Account_Model.AccountLOD7 =
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN Child.Account
				WHEN ''6'' THEN Child.Account
				WHEN ''7'' THEN Child.Account
				WHEN ''8'' THEN  (
					ISNULL((SELECT 
						L7.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L7
					WHERE 
						L7.SourceID = Child.SourceID AND
						L7.Account = Child.AccountParent AND
						L7.AccountLevelOfDetail BETWEEN ''7'' AND ''7''),Child.Account))
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L7.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L7,
						RD_Common.dbo.Star_Account_Model L8
					WHERE 
						L7.SourceID = Child.SourceID AND
						L8.SourceID = Child.SourceID AND
						L7.Account = L8.AccountParent AND
						L8.Account = Child.AccountParent AND
						L7.AccountLevelOfDetail BETWEEN ''7'' AND ''8''),
					ISNULL((SELECT 
						L7.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L7
					WHERE 
						L7.SourceID = Child.SourceID AND
						L7.Account = Child.AccountParent AND
						L7.AccountLevelOfDetail BETWEEN ''7'' AND ''8''),Child.Account)))
				END,
		RD_Common.dbo.Star_Account_Model.AccountLOD8 = 
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN Child.Account
				WHEN ''6'' THEN Child.Account
				WHEN ''7'' THEN Child.Account
				WHEN ''8'' THEN Child.Account
				WHEN ''9'' THEN  (
					ISNULL((SELECT 
						L8.Account
					FROM 
						RD_Common.dbo.Star_Account_Model L8
					WHERE 
						L8.SourceID = Child.SourceID AND
						L8.Account = Child.AccountParent AND
						L8.AccountLevelOfDetail BETWEEN ''8'' AND ''8''),Child.Account))
				END,
		RD_Common.dbo.Star_Account_Model.AccountLOD9 =
			CASE Child.AccountLevelOfDetail
				WHEN ''3'' THEN Child.Account
				WHEN ''4'' THEN Child.Account
				WHEN ''5'' THEN Child.Account
				WHEN ''6'' THEN Child.Account
				WHEN ''7'' THEN Child.Account
				WHEN ''8'' THEN Child.Account
				WHEN ''9'' THEN Child.Account
				END
	FROM 
		RD_Common.dbo.Star_Account_Model AS Child




----------------------------------------------------------------------------------------------------------------------------------------------------------------
-- UPDATE Level of Detail Descriptions LOD 3-9 
----------------------------------------------------------------------------------------------------------------------------------------------------------------


UPDATE 
RD_Common.dbo.Star_Account_Model
	SET 
		AccountLOD3Desc = Acc.AccountDesc
	FROM 
		RD_Common.dbo.Star_Account_Model  INNER JOIN 
		RD_Common.dbo.Star_Account_Model Acc ON
				(RD_Common.dbo.Star_Account_Model.AccountLOD3 = Acc.Account) AND 
				RD_Common.dbo.Star_Account_Model.SourceID = Acc.SourceID
UPDATE 
RD_Common.dbo.Star_Account_Model
	SET 
		AccountLOD4Desc = Acc.AccountDesc
	FROM 
		RD_Common.dbo.Star_Account_Model  INNER JOIN 
		RD_Common.dbo.Star_Account_Model Acc ON
				(RD_Common.dbo.Star_Account_Model.AccountLOD4 = Acc.Account) AND 
				RD_Common.dbo.Star_Account_Model.SourceID = Acc.SourceID

UPDATE 
RD_Common.dbo.Star_Account_Model
	SET 
		AccountLOD5Desc = Acc.AccountDesc
	FROM 
		RD_Common.dbo.Star_Account_Model  INNER JOIN 
		RD_Common.dbo.Star_Account_Model Acc ON
				(RD_Common.dbo.Star_Account_Model.AccountLOD5 = Acc.Account) AND 
				RD_Common.dbo.Star_Account_Model.SourceID = Acc.SourceID

UPDATE 
RD_Common.dbo.Star_Account_Model
	SET 
		AccountLOD6Desc = Acc.AccountDesc
	FROM 
		RD_Common.dbo.Star_Account_Model  INNER JOIN 
		RD_Common.dbo.Star_Account_Model Acc ON
				(RD_Common.dbo.Star_Account_Model.AccountLOD6 = Acc.Account) AND 
				RD_Common.dbo.Star_Account_Model.SourceID = Acc.SourceID

UPDATE 
RD_Common.dbo.Star_Account_Model
	SET 
		AccountLOD7Desc = Acc.AccountDesc
	FROM 
		RD_Common.dbo.Star_Account_Model  INNER JOIN 
		RD_Common.dbo.Star_Account_Model Acc ON
				(RD_Common.dbo.Star_Account_Model.AccountLOD7 = Acc.Account) AND 
				RD_Common.dbo.Star_Account_Model.SourceID = Acc.SourceID

UPDATE 
RD_Common.dbo.Star_Account_Model
	SET 
		AccountLOD8Desc = Acc.AccountDesc
	FROM 
		RD_Common.dbo.Star_Account_Model  INNER JOIN 
		RD_Common.dbo.Star_Account_Model Acc ON
				(RD_Common.dbo.Star_Account_Model.AccountLOD8 = Acc.Account) AND 
				RD_Common.dbo.Star_Account_Model.SourceID = Acc.SourceID

UPDATE 
RD_Common.dbo.Star_Account_Model
	SET 
		AccountLOD9Desc = Acc.AccountDesc
	FROM 
		RD_Common.dbo.Star_Account_Model  INNER JOIN 
		RD_Common.dbo.Star_Account_Model Acc ON
				(RD_Common.dbo.Star_Account_Model.AccountLOD9 = Acc.Account) AND 
				RD_Common.dbo.Star_Account_Model.SourceID = Acc.SourceID
' 
END
GO
/****** Object:  StoredProcedure [dbo].[USP_Star_Company_Refresh]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_Star_Company_Refresh]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE       PROCEDURE [dbo].[USP_Star_Company_Refresh]
----------------------------------------------------------------------------------------------------
--	Author:			c Copyright 2004 Andrews Consulting Group 
--	Procedure:		USP_Star_Company_Refresh
--
--	Description:		User Stored Procedure To Update RD_Common.dbo.Star_Company
--				Dimension Category Codes and Descriptions.  This User	
--				Stored Procedure Must Be Executed After Refresh Of 
-- 				The RD_Common.dbo.Star_Company Table. 
--
--	Application:		RD_Common Data Mart
--
--
--Modification History
--
--Date			Modified By		Description
--01.01.2001 		<developer name>	<comments>
-----------------------------------------------------------------------------------------------------------
AS

--EXEC master.dbo.xp_logevent 65000,''Beginning of Company After refresh Procedure'',Informational

UPDATE RD_Common.dbo.Star_Company
SET
	CompanyLevel01Code 	= Category01Code,
	CompanyLevel01 		= Category01,
	CompanyLevel02Code 	= Category02Code,
	CompanyLevel02 		= Category02,
	CompanyLevel03Code 	= Category03Code,
	CompanyLevel03 		= Category03,
 	CompanyLevel04Code 	= Category04Code,
	CompanyLevel04 		= Category04,
	CompanyLevel05Code 	= Category05Code,
	CompanyLevel05 		= Category05,
	CompanyLevel06Code 	= Category06Code,
	CompanyLevel06 		= Category06,
	CompanyLevel07Code 	= Category07Code,
	CompanyLevel07	 	= Category07,
	CompanyLevel08Code 	= Category08Code,
	CompanyLevel08 		= Category08,
	CompanyLevel09Code 	= Category09Code,
	CompanyLevel09	 	= Category09,
	CompanyLevel10Code 	= Category10Code,
	CompanyLevel10	 	= Category10,
	CompanyLevel11Code 	= Category11Code,
	CompanyLevel11 		= Category11,
	CompanyLevel12Code 	= Category12Code,
	CompanyLevel12	 	= Category12,
	CompanyLevel13Code 	= Category13Code,
	CompanyLevel13	 	= Category13,
	CompanyLevel14Code 	= Category14Code,
	CompanyLevel14	 	= Category14,
	CompanyLevel15Code 	= Category15Code,
	CompanyLevel15 		= Category15,
	CompanyLevel16Code 	= Category16Code,
	CompanyLevel16	 	= Category16,
	CompanyLevel17Code 	= Category17Code,
	CompanyLevel17	 	= Category17,
	CompanyLevel18Code 	= Category18Code,
	CompanyLevel18	 	= Category18,
	CompanyLevel19Code 	= Category19Code,
	CompanyLevel19	 	= Category19,
	CompanyLevel20Code 	= Category20Code,
	CompanyLevel20	 	= Category20,
	CompanyLevel21Code 	= Category21Code,
	CompanyLevel21	 	= Category21,
	CompanyLevel22Code 	= Category22Code,
	CompanyLevel22	 	= Category22,
	CompanyLevel23Code 	= Category23Code,
	CompanyLevel23	 	= Category23,
	CompanyLevel24Code 	= Category24Code,
	CompanyLevel24	 	= Category24,
	CompanyLevel25Code 	= Category25Code,
	CompanyLevel25	 	= Category25,
	CompanyLevel26Code 	= Category26Code,
	CompanyLevel26	 	= Category26,
	CompanyLevel27Code 	= Category27Code,
	CompanyLevel27	 	= Category27,
	CompanyLevel28Code 	= Category28Code,
	CompanyLevel28	 	= Category28,
	CompanyLevel29Code 	= Category29Code,
	CompanyLevel29	 	= Category29,
	CompanyLevel30Code 	= Category30Code,
	CompanyLevel30 		= Category30
FROM RD_Common.dbo.Star_Company SC
	INNER JOIN  RD_Common.dbo.Star_BusinessUnit SBU
		ON (LTRIM(SBU.BusinessUnitCode) = REPLACE (LTRIM(REPLACE(SC.CompanyNumber,''0'','' '')),'' '',''0'') AND
		SBU.SourceID = SC.SourceID)

--EXEC master.dbo.xp_logevent 65000,''End of Company After refresh Procedure'',Informational
' 
END
GO
/****** Object:  Table [dbo].[AR_Star_Customer]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AR_Star_Customer]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[AR_Star_Customer](
	[CustomerNumberID] [bigint] NOT NULL,
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[CustomerNumber] [int] NOT NULL,
	[CompanyNumber] [char](5) NOT NULL,
	[CustomerName] [char](40) NOT NULL,
	[BillToNumber] [int] NOT NULL,
	[BillToName] [char](40) NOT NULL,
	[BillToAddressLine01] [char](40) NOT NULL,
	[BillToAddressLine02] [char](40) NOT NULL,
	[BillToAddressLine03] [char](40) NOT NULL,
	[BillToAddressLine04] [char](40) NOT NULL,
	[BillToPostalCode] [char](12) NOT NULL,
	[BillToCity] [char](25) NOT NULL,
	[BillToStateCode] [char](3) NOT NULL,
	[BillToState] [char](30) NOT NULL,
	[BillToCountryCode] [char](3) NOT NULL,
	[BillToCountry] [char](30) NOT NULL,
	[BillToCounty] [char](25) NOT NULL,
	[ParentNumber] [int] NOT NULL,
	[ParentName] [char](40) NOT NULL,
	[ParentAddressLine01] [char](40) NOT NULL,
	[ParentAddressLine02] [char](40) NOT NULL,
	[ParentAddressLine03] [char](40) NOT NULL,
	[ParentAddressLine04] [char](40) NOT NULL,
	[ParentPostalCode] [char](12) NOT NULL,
	[ParentCity] [char](25) NOT NULL,
	[ParentCounty] [char](25) NOT NULL,
	[ParentStateCode] [char](3) NOT NULL,
	[ParentState] [char](30) NOT NULL,
	[ParentCountry] [char](30) NOT NULL,
	[ParentCountryCode] [char](3) NOT NULL,
	[AlternatePayer] [int] NOT NULL,
	[AverageDaysToPay] [int] NOT NULL,
	[AmountInvoicedThisYear] [decimal](20, 7) NOT NULL,
	[LastPaidAmount] [decimal](20, 7) NOT NULL,
	[DateLastPaid] [datetime] NOT NULL,
	[RelatedAddressNumber] [int] NOT NULL,
	[CreditLimit] [decimal](20, 7) NOT NULL,
	[RouteCode] [char](3) NOT NULL,
	[ROUTECODEDescription] [varchar](255) NOT NULL,
	[HoldOrdersCode] [char](2) NOT NULL,
	[HOLDORDERSCODEDescription] [varchar](255) NOT NULL,
	[StopCode] [char](3) NOT NULL,
	[DELIVERYDAY] [varchar](255) NOT NULL,
	[HoldInvoices] [char](1) NOT NULL,
	[Category01Code] [char](3) NOT NULL,
	[Category01] [varchar](255) NOT NULL,
	[Category02Code] [char](3) NOT NULL,
	[Category02] [varchar](255) NOT NULL,
	[Category03Code] [char](3) NOT NULL,
	[Category03] [varchar](255) NOT NULL,
	[Category04Code] [char](3) NOT NULL,
	[Category04] [varchar](255) NOT NULL,
	[Category05Code] [char](3) NOT NULL,
	[Category05] [varchar](255) NOT NULL,
	[Category06Code] [char](3) NOT NULL,
	[Category06] [varchar](255) NOT NULL,
	[Category07Code] [char](3) NOT NULL,
	[Category07] [varchar](255) NOT NULL,
	[Category08Code] [char](3) NOT NULL,
	[Category08] [varchar](255) NOT NULL,
	[Category09Code] [char](3) NOT NULL,
	[Category09] [varchar](255) NOT NULL,
	[Category10Code] [char](3) NOT NULL,
	[Category10] [varchar](255) NOT NULL,
	[Category11Code] [char](3) NOT NULL,
	[Category11] [varchar](255) NOT NULL,
	[Category12Code] [char](3) NOT NULL,
	[Category12] [varchar](255) NOT NULL,
	[Category13Code] [char](3) NOT NULL,
	[Category13] [varchar](255) NOT NULL,
	[Category14Code] [char](3) NOT NULL,
	[Category14] [varchar](255) NOT NULL,
	[Category15Code] [char](3) NOT NULL,
	[Category15] [varchar](255) NOT NULL,
	[Category16Code] [char](3) NOT NULL,
	[Category16] [varchar](255) NOT NULL,
	[Category17Code] [char](3) NOT NULL,
	[Category17] [varchar](255) NOT NULL,
	[Category18Code] [char](3) NOT NULL,
	[Category18] [varchar](255) NOT NULL,
	[Category19Code] [char](3) NOT NULL,
	[Category19] [varchar](255) NOT NULL,
	[Category20Code] [char](3) NOT NULL,
	[Category20] [varchar](255) NOT NULL,
	[Category21Code] [char](3) NOT NULL,
	[Category21] [varchar](255) NOT NULL,
	[Category22Code] [char](3) NOT NULL,
	[Category22] [varchar](255) NOT NULL,
	[Category23Code] [char](3) NOT NULL,
	[Category23] [varchar](255) NOT NULL,
	[Category24Code] [char](3) NOT NULL,
	[Category24] [varchar](255) NOT NULL,
	[Category25Code] [char](3) NOT NULL,
	[Category25] [varchar](255) NOT NULL,
	[Category26Code] [char](3) NOT NULL,
	[Category26] [varchar](255) NOT NULL,
	[Category27Code] [char](3) NOT NULL,
	[Category27] [varchar](255) NOT NULL,
	[Category28Code] [char](3) NOT NULL,
	[Category28] [varchar](255) NOT NULL,
	[Category29Code] [char](3) NOT NULL,
	[Category29] [varchar](255) NOT NULL,
	[Category30Code] [char](3) NOT NULL,
	[Category30] [varchar](255) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
	[DateOfFirstInvoice] [bigint] NULL,
	[LastInvoiceDate] [bigint] NULL,
	[LastStatementDate] [bigint] NULL
) ON [PRIMARY]
WITH
(
DATA_COMPRESSION = PAGE
)
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[DeliveryDayCodeDetails]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DeliveryDayCodeDetails]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[DeliveryDayCodeDetails](
	[DeliveryCycle] [varchar](10) NOT NULL,
	[Frequency] [varchar](3) NOT NULL,
	[Days] [int] NOT NULL
) ON [PRIMARY]
WITH
(
DATA_COMPRESSION = PAGE
)
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[MasterDeliveryDateCalendar]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MasterDeliveryDateCalendar]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[MasterDeliveryDateCalendar](
	[Delivery Date] [datetime] NULL,
	[Delivery Cycle] [varchar](10) NULL,
	[Date Of Week] [varchar](30) NULL
) ON [PRIMARY]
WITH
(
DATA_COMPRESSION = PAGE
)
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Orphans]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Orphans]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Orphans](
	[Mart] [varchar](15) NOT NULL,
	[RunDate] [datetime] NOT NULL,
	[OrphanType] [varchar](50) NOT NULL,
	[Value] [varchar](50) NOT NULL,
	[NumberOfOrphans] [int] NOT NULL,
 CONSTRAINT [PK_Orphans] PRIMARY KEY CLUSTERED 
(
	[Mart] ASC,
	[RunDate] ASC,
	[OrphanType] ASC,
	[Value] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Sales_Star_Customer]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Sales_Star_Customer](
	[CustomerNumberID] [bigint] NOT NULL,
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[ParentNumber] [int] NOT NULL,
	[ParentName] [char](40) NOT NULL,
	[ParentAddressLine01] [char](40) NOT NULL,
	[ParentAddressLine02] [char](40) NOT NULL,
	[ParentAddressLine03] [char](40) NOT NULL,
	[ParentAddressLine04] [char](40) NOT NULL,
	[ParentPostalCode] [char](12) NOT NULL,
	[ParentCity] [char](25) NOT NULL,
	[ParentCounty] [char](25) NOT NULL,
	[ParentStateCode] [char](3) NOT NULL,
	[ParentState] [char](30) NOT NULL,
	[ParentCountry] [char](30) NOT NULL,
	[ParentCountryCode] [char](3) NOT NULL,
	[InvoicetoNumber] [int] NOT NULL,
	[InvoicetoName] [char](40) NOT NULL,
	[InvoicetoAddressLine01] [char](40) NOT NULL,
	[InvoicetoAddressLine02] [char](40) NOT NULL,
	[InvoicetoAddressLine03] [char](40) NOT NULL,
	[InvoicetoAddressLine04] [char](40) NOT NULL,
	[InvoicetoPostalCode] [char](12) NOT NULL,
	[InvoicetoCity] [char](25) NOT NULL,
	[InvoicetoCounty] [char](25) NOT NULL,
	[InvoicetoStateCode] [char](3) NOT NULL,
	[InvoicetoState] [char](30) NOT NULL,
	[InvoicetoCountry] [char](30) NOT NULL,
	[InvoicetoCountryCode] [char](3) NOT NULL,
	[InvoicetoSearchTypeCode] [char](3) NOT NULL,
	[InvoicetoSearchType] [char](30) NOT NULL,
	[SoldtoNumber] [int] NOT NULL,
	[SoldtoName] [char](40) NOT NULL,
	[SoldtoAddressLine01] [char](40) NOT NULL,
	[SoldtoAddressLine02] [char](40) NOT NULL,
	[SoldtoAddressLine03] [char](40) NOT NULL,
	[SoldtoAddressLine04] [char](40) NOT NULL,
	[SoldtoPostalCode] [char](12) NOT NULL,
	[SoldtoCity] [char](25) NOT NULL,
	[SoldtoCounty] [char](25) NOT NULL,
	[SoldtoStateCode] [char](3) NOT NULL,
	[SoldtoState] [char](30) NOT NULL,
	[SoldtoCountry] [char](30) NOT NULL,
	[SoldtoCountryCode] [char](3) NOT NULL,
	[SoldtoSearchTypeCode] [char](3) NOT NULL,
	[SoldtoSearchType] [char](30) NOT NULL,
	[ShiptoNumber] [int] NOT NULL,
	[ShiptoName] [char](40) NOT NULL,
	[ShiptoAddressLine01] [char](40) NOT NULL,
	[ShiptoAddressLine02] [char](40) NOT NULL,
	[ShiptoAddressLine03] [char](40) NOT NULL,
	[ShiptoAddressLine04] [char](40) NOT NULL,
	[ShiptoPostalCode] [char](12) NOT NULL,
	[ShiptoCity] [char](25) NOT NULL,
	[ShiptoCounty] [char](25) NOT NULL,
	[ShiptoStateCode] [char](3) NOT NULL,
	[ShiptoState] [char](30) NOT NULL,
	[ShiptoCountry] [char](30) NOT NULL,
	[ShiptoCountryCode] [char](3) NOT NULL,
	[ShiptoSearchTypeCode] [char](3) NOT NULL,
	[ShiptoSearchType] [char](30) NOT NULL,
	[RelatedAddressNumber] [int] NOT NULL,
	[CompanyNumber] [char](5) NOT NULL,
	[CreditLimit] [decimal](20, 7) NOT NULL,
	[RouteCode] [char](3) NOT NULL,
	[ROUTECODEDescription] [varchar](255) NOT NULL,
	[HoldOrdersCode] [char](2) NOT NULL,
	[HOLDORDERSCODEDescription] [varchar](255) NOT NULL,
	[StopCode] [char](3) NOT NULL,
	[DELIVERYDAY] [varchar](255) NOT NULL,
	[HoldInvoices] [char](1) NOT NULL,
	[Category01Code] [char](3) NOT NULL,
	[Category01] [varchar](255) NOT NULL,
	[Category02Code] [char](3) NOT NULL,
	[Category02] [varchar](255) NOT NULL,
	[Category03Code] [char](3) NOT NULL,
	[Category03] [varchar](255) NOT NULL,
	[Category04Code] [char](3) NOT NULL,
	[Category04] [varchar](255) NOT NULL,
	[Category05Code] [char](3) NOT NULL,
	[Category05] [varchar](255) NOT NULL,
	[Category06Code] [char](3) NOT NULL,
	[Category06] [varchar](255) NOT NULL,
	[Category07Code] [char](3) NOT NULL,
	[Category07] [varchar](255) NOT NULL,
	[Category08Code] [char](3) NOT NULL,
	[Category08] [varchar](255) NOT NULL,
	[Category09Code] [char](3) NOT NULL,
	[Category09] [varchar](255) NOT NULL,
	[Category10Code] [char](3) NOT NULL,
	[Category10] [varchar](255) NOT NULL,
	[Category11Code] [char](3) NOT NULL,
	[Category11] [varchar](255) NOT NULL,
	[Category12Code] [char](3) NOT NULL,
	[Category12] [varchar](255) NOT NULL,
	[Category13Code] [char](3) NOT NULL,
	[Category13] [varchar](255) NOT NULL,
	[Category14Code] [char](3) NOT NULL,
	[Category14] [varchar](255) NOT NULL,
	[Category15Code] [char](3) NOT NULL,
	[Category15] [varchar](255) NOT NULL,
	[Category16Code] [char](3) NOT NULL,
	[Category16] [varchar](255) NOT NULL,
	[Category17Code] [char](3) NOT NULL,
	[Category17] [varchar](255) NOT NULL,
	[Category18Code] [char](3) NOT NULL,
	[Category18] [varchar](255) NOT NULL,
	[Category19Code] [char](3) NOT NULL,
	[Category19] [varchar](255) NOT NULL,
	[Category20Code] [char](3) NOT NULL,
	[Category20] [varchar](255) NOT NULL,
	[Category21Code] [char](3) NOT NULL,
	[Category21] [varchar](255) NOT NULL,
	[Category22Code] [char](3) NOT NULL,
	[Category22] [varchar](255) NOT NULL,
	[Category23Code] [char](3) NOT NULL,
	[Category23] [varchar](255) NOT NULL,
	[Category24Code] [char](3) NOT NULL,
	[Category24] [varchar](255) NOT NULL,
	[Category25Code] [char](3) NOT NULL,
	[Category25] [varchar](255) NOT NULL,
	[Category26Code] [char](3) NOT NULL,
	[Category26] [varchar](255) NOT NULL,
	[Category27Code] [char](3) NOT NULL,
	[Category27] [varchar](255) NOT NULL,
	[Category28Code] [char](3) NOT NULL,
	[Category28] [varchar](255) NOT NULL,
	[Category29Code] [char](3) NOT NULL,
	[Category29] [varchar](255) NOT NULL,
	[Category30Code] [char](3) NOT NULL,
	[Category30] [varchar](255) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
	[DateOfFirstInvoice] [bigint] NULL,
	[LastInvoiceDate] [bigint] NULL,
	[LastStatementDate] [bigint] NULL,
 CONSTRAINT [PK_Sales_Star_Customer] PRIMARY KEY CLUSTERED 
(
	[CustomerNumberID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_Account]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_Account]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_Account](
	[AIDID] [bigint] NOT NULL,
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[AID] [char](8) NOT NULL,
	[Account] [char](15) NOT NULL,
	[AccountDesc] [char](30) NOT NULL,
	[BusinessUnitCode] [char](12) NOT NULL,
	[CompanyNumber] [char](5) NOT NULL,
	[Object] [char](6) NOT NULL,
	[Subsidiary] [char](8) NOT NULL,
	[FlexAccount] [char](25) NOT NULL,
	[Description01] [char](30) NOT NULL,
	[AccountLevelOfDetail] [char](1) NOT NULL,
	[BudgetPatternCode] [char](3) NOT NULL,
	[PostingEditCode] [char](1) NOT NULL,
	[PostingEditCodeDescription] [char](30) NOT NULL,
	[Billable] [char](1) NOT NULL,
	[CurrencyCode] [char](3) NOT NULL,
	[UnitOfMeasure] [char](2) NOT NULL,
	[AccountParent] [char](15) NULL,
	[AccountParentDesc] [char](30) NULL,
	[AccountLOD3] [char](15) NULL,
	[AccountLOD3Desc] [char](30) NULL,
	[AccountLOD4] [char](15) NULL,
	[AccountLOD4Desc] [char](30) NULL,
	[AccountLOD5] [char](15) NULL,
	[AccountLOD5Desc] [char](30) NULL,
	[AccountLOD6] [char](15) NULL,
	[AccountLOD6Desc] [char](30) NULL,
	[AccountLOD7] [char](15) NULL,
	[AccountLOD7Desc] [char](30) NULL,
	[AccountLOD8] [char](15) NULL,
	[AccountLOD8Desc] [char](30) NULL,
	[AccountLOD9] [char](15) NULL,
	[AccountLOD9Desc] [char](30) NULL,
	[Category01Code] [char](3) NOT NULL,
	[Category01] [char](30) NOT NULL,
	[Category02Code] [char](3) NOT NULL,
	[Category02] [char](30) NOT NULL,
	[Category03Code] [char](3) NOT NULL,
	[Category03] [char](30) NOT NULL,
	[Category04Code] [char](3) NOT NULL,
	[Category04] [char](30) NOT NULL,
	[Category05Code] [char](3) NOT NULL,
	[Category05] [char](30) NOT NULL,
	[Category06Code] [char](3) NOT NULL,
	[Category06] [char](30) NOT NULL,
	[Category07Code] [char](3) NOT NULL,
	[Category07] [char](30) NOT NULL,
	[Category08Code] [char](3) NOT NULL,
	[Category08] [char](30) NOT NULL,
	[Category09Code] [char](3) NOT NULL,
	[Category09] [char](30) NOT NULL,
	[Category10Code] [char](3) NOT NULL,
	[Category10] [char](30) NOT NULL,
	[Category11Code] [char](3) NOT NULL,
	[Category11] [char](30) NOT NULL,
	[Category12Code] [char](3) NOT NULL,
	[Category12] [char](30) NOT NULL,
	[Category13Code] [char](3) NOT NULL,
	[Category13] [char](30) NOT NULL,
	[Category14Code] [char](3) NOT NULL,
	[Category14] [char](30) NOT NULL,
	[Category15Code] [char](3) NOT NULL,
	[Category15] [char](30) NOT NULL,
	[Category16Code] [char](3) NOT NULL,
	[Category16] [char](30) NOT NULL,
	[Category17Code] [char](3) NOT NULL,
	[Category17] [char](30) NOT NULL,
	[Category18Code] [char](3) NOT NULL,
	[Category18] [char](30) NOT NULL,
	[Category19Code] [char](3) NOT NULL,
	[Category19] [char](30) NOT NULL,
	[Category20Code] [char](3) NOT NULL,
	[Category20] [char](30) NOT NULL,
	[Category21Code] [char](10) NOT NULL,
	[Category21] [char](30) NOT NULL,
	[Category22Code] [char](10) NOT NULL,
	[Category22] [char](30) NOT NULL,
	[Category23Code] [char](10) NOT NULL,
	[Category23] [char](30) NOT NULL,
	[AlternateObject] [char](6) NOT NULL,
	[AlternateSubsidiary] [char](8) NOT NULL,
	[WorkersComp] [char](4) NOT NULL,
	[MethodOfComputation] [char](1) NOT NULL,
	[EquipmentRateCode] [char](2) NOT NULL,
	[HeaderTypeCode] [char](1) NOT NULL,
	[LevelOfDetailQuantityRollUp] [char](1) NOT NULL,
	[CostCodeComplete] [char](1) NOT NULL,
	[ModelAccountConsolidations] [char](1) NOT NULL,
	[UserID] [char](10) NOT NULL,
	[ProgramID] [char](10) NOT NULL,
	[WorkStationID] [char](10) NOT NULL,
	[DateUpdated] [datetime] NOT NULL,
	[LastTimeUpdated] [int] NOT NULL,
	[CostObjectEditCode01] [char](1) NOT NULL,
	[CostObjectEditCode02] [char](1) NOT NULL,
	[CostObjectEditCode03] [char](1) NOT NULL,
	[CostObjectEditCode04] [char](1) NOT NULL,
	[ItemEditCode] [char](1) NOT NULL,
	[FixedAssetPostingEditCode] [char](1) NOT NULL,
	[TypeCode] [char](1) NOT NULL,
	[GLAccountTaxableFlag] [char](1) NOT NULL,
	[TargetObjectAccount] [char](6) NOT NULL,
	[TargetSubsidiary] [char](8) NOT NULL,
	[PurgeFlag] [char](1) NOT NULL,
	[TaxRateArea] [char](10) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
	[Category15Desc2] [char](30) NOT NULL,
	[Category16Desc2] [char](30) NOT NULL,
	[Category17Desc2] [char](30) NOT NULL,
	[Category18Desc2] [char](30) NOT NULL,
 CONSTRAINT [PK_Star_Account] PRIMARY KEY CLUSTERED 
(
	[AID] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_Account_Model]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_Account_Model]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_Account_Model](
	[AccountID] [char](20) NOT NULL,
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[AID] [char](8) NOT NULL,
	[Account] [char](15) NOT NULL,
	[AccountDesc] [char](30) NOT NULL,
	[BusinessUnitCode] [char](12) NOT NULL,
	[CompanyNumber] [char](5) NOT NULL,
	[Object] [char](6) NOT NULL,
	[Subsidiary] [char](8) NOT NULL,
	[FlexAccount] [char](25) NOT NULL,
	[Description01] [char](30) NOT NULL,
	[AccountLevelOfDetail] [char](1) NOT NULL,
	[BudgetPatternCode] [char](3) NOT NULL,
	[PostingEditCode] [char](1) NOT NULL,
	[PostingEditCodeDescription] [char](30) NOT NULL,
	[Billable] [char](1) NOT NULL,
	[CurrencyCode] [char](3) NOT NULL,
	[UnitOfMeasure] [char](2) NOT NULL,
	[AccountParent] [char](15) NULL,
	[AccountParentDesc] [char](30) NULL,
	[AccountLOD3] [char](15) NULL,
	[AccountLOD3Desc] [char](30) NULL,
	[AccountLOD4] [char](15) NULL,
	[AccountLOD4Desc] [char](30) NULL,
	[AccountLOD5] [char](15) NULL,
	[AccountLOD5Desc] [char](30) NULL,
	[AccountLOD6] [char](15) NULL,
	[AccountLOD6Desc] [char](30) NULL,
	[AccountLOD7] [char](15) NULL,
	[AccountLOD7Desc] [char](30) NULL,
	[AccountLOD8] [char](15) NULL,
	[AccountLOD8Desc] [char](30) NULL,
	[AccountLOD9] [char](15) NULL,
	[AccountLOD9Desc] [char](30) NULL,
	[Category01Code] [char](3) NOT NULL,
	[Category01] [char](30) NOT NULL,
	[Category02Code] [char](3) NOT NULL,
	[Category02] [char](30) NOT NULL,
	[Category03Code] [char](3) NOT NULL,
	[Category03] [char](30) NOT NULL,
	[Category04Code] [char](3) NOT NULL,
	[Category04] [char](30) NOT NULL,
	[Category05Code] [char](3) NOT NULL,
	[Category05] [char](30) NOT NULL,
	[Category06Code] [char](3) NOT NULL,
	[Category06] [char](30) NOT NULL,
	[Category07Code] [char](3) NOT NULL,
	[Category07] [char](30) NOT NULL,
	[Category08Code] [char](3) NOT NULL,
	[Category08] [char](30) NOT NULL,
	[Category09Code] [char](3) NOT NULL,
	[Category09] [char](30) NOT NULL,
	[Category10Code] [char](3) NOT NULL,
	[Category10] [char](30) NOT NULL,
	[Category11Code] [char](3) NOT NULL,
	[Category11] [char](30) NOT NULL,
	[Category12Code] [char](3) NOT NULL,
	[Category12] [char](30) NOT NULL,
	[Category13Code] [char](3) NOT NULL,
	[Category13] [char](30) NOT NULL,
	[Category14Code] [char](3) NOT NULL,
	[Category14] [char](30) NOT NULL,
	[Category15Code] [char](3) NOT NULL,
	[Category15] [char](30) NOT NULL,
	[Category16Code] [char](3) NOT NULL,
	[Category16] [char](30) NOT NULL,
	[Category17Code] [char](3) NOT NULL,
	[Category17] [char](30) NOT NULL,
	[Category18Code] [char](3) NOT NULL,
	[Category18] [char](30) NOT NULL,
	[Category19Code] [char](3) NOT NULL,
	[Category19] [char](30) NOT NULL,
	[Category20Code] [char](3) NOT NULL,
	[Category20] [char](30) NOT NULL,
	[Category21Code] [char](10) NOT NULL,
	[Category21] [char](30) NOT NULL,
	[Category22Code] [char](10) NOT NULL,
	[Category22] [char](30) NOT NULL,
	[Category23Code] [char](10) NOT NULL,
	[Category23] [char](30) NOT NULL,
	[AlternateObject] [char](6) NOT NULL,
	[AlternateSubsidiary] [char](8) NOT NULL,
	[WorkersComp] [char](4) NOT NULL,
	[MethodOfComputation] [char](1) NOT NULL,
	[EquipmentRateCode] [char](2) NOT NULL,
	[HeaderTypeCode] [char](1) NOT NULL,
	[LevelOfDetailQuantityRollUp] [char](1) NOT NULL,
	[CostCodeComplete] [char](1) NOT NULL,
	[ModelAccountConsolidations] [char](1) NOT NULL,
	[UserID] [char](10) NOT NULL,
	[ProgramID] [char](10) NOT NULL,
	[WorkStationID] [char](10) NOT NULL,
	[DateUpdated] [datetime] NOT NULL,
	[LastTimeUpdated] [int] NOT NULL,
	[CostObjectEditCode01] [char](1) NOT NULL,
	[CostObjectEditCode02] [char](1) NOT NULL,
	[CostObjectEditCode03] [char](1) NOT NULL,
	[CostObjectEditCode04] [char](1) NOT NULL,
	[ItemEditCode] [char](1) NOT NULL,
	[FixedAssetPostingEditCode] [char](1) NOT NULL,
	[TypeCode] [char](1) NOT NULL,
	[GLAccountTaxableFlag] [char](1) NOT NULL,
	[TargetObjectAccount] [char](6) NOT NULL,
	[TargetSubsidiary] [char](8) NOT NULL,
	[PurgeFlag] [char](1) NOT NULL,
	[TaxRateArea] [char](10) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
	[Category15Desc2] [char](30) NOT NULL,
	[Category16Desc2] [char](30) NOT NULL,
	[Category17Desc2] [char](30) NOT NULL,
	[Category18Desc2] [char](30) NOT NULL,
 CONSTRAINT [PK_Star_Account_Model] PRIMARY KEY CLUSTERED 
(
	[Account] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_AddressBook]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_AddressBook]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_AddressBook](
	[AddressNumberID] [bigint] NOT NULL,
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[AddressNumber] [int] NOT NULL,
	[LongAddressNumber] [char](20) NOT NULL,
	[TaxID] [char](20) NOT NULL,
	[AlphaName] [char](40) NOT NULL,
	[DescriptionCompressed] [char](40) NOT NULL,
	[BusinessUnitCode] [char](12) NOT NULL,
	[StandardIndustryCode] [char](10) NOT NULL,
	[LanguagePreferenceCode] [char](2) NOT NULL,
	[LanguagePreference] [char](30) NOT NULL,
	[SearchTypeCode] [char](3) NOT NULL,
	[SearchType] [char](30) NOT NULL,
	[CreditMessageCode] [char](2) NOT NULL,
	[CreditMessage] [char](30) NOT NULL,
	[PersonCorpTaxpayerCode] [char](1) NOT NULL,
	[ARAPNetting] [char](1) NOT NULL,
	[AddressType3YN] [char](1) NOT NULL,
	[AddressType4YN] [char](1) NOT NULL,
	[AddressType5YN] [char](1) NOT NULL,
	[Payables] [char](1) NOT NULL,
	[Receivables] [char](1) NOT NULL,
	[UserCode] [char](1) NOT NULL,
	[MiscCode3] [char](1) NOT NULL,
	[Employee] [char](1) NOT NULL,
	[SubledgerInactiveCode] [char](1) NOT NULL,
	[StartEffectiveDate] [datetime] NOT NULL,
	[RelatedAddressNumber1] [int] NOT NULL,
	[RelatedAddressNumber2] [int] NOT NULL,
	[RelatedAddressNumber3] [int] NOT NULL,
	[RelatedAddressNumber4] [int] NOT NULL,
	[RelatedAddressNumber5] [int] NOT NULL,
	[FactorSpecialPayee] [int] NOT NULL,
	[Category01Code] [char](3) NOT NULL,
	[Category01] [char](30) NOT NULL,
	[Category02Code] [char](3) NOT NULL,
	[Category02] [char](30) NOT NULL,
	[Category03Code] [char](3) NOT NULL,
	[Category03] [char](30) NOT NULL,
	[Category04Code] [char](3) NOT NULL,
	[Category04] [char](30) NOT NULL,
	[Category05Code] [char](3) NOT NULL,
	[Category05] [char](30) NOT NULL,
	[Category06Code] [char](3) NOT NULL,
	[Category06] [char](30) NOT NULL,
	[Category07Code] [char](3) NOT NULL,
	[Category07] [char](30) NOT NULL,
	[Category08Code] [char](3) NOT NULL,
	[Category08] [char](30) NOT NULL,
	[Category09Code] [char](3) NOT NULL,
	[Category09] [char](30) NOT NULL,
	[Category10Code] [char](3) NOT NULL,
	[Category10] [char](30) NOT NULL,
	[Category11Code] [char](3) NOT NULL,
	[Category11] [char](30) NOT NULL,
	[Category12Code] [char](3) NOT NULL,
	[Category12] [char](30) NOT NULL,
	[Category13Code] [char](3) NOT NULL,
	[Category13] [char](30) NOT NULL,
	[Category14Code] [char](3) NOT NULL,
	[Category14] [char](30) NOT NULL,
	[Category15Code] [char](3) NOT NULL,
	[Category15] [char](30) NOT NULL,
	[Category16Code] [char](3) NOT NULL,
	[Category16] [char](30) NOT NULL,
	[Category17Code] [char](3) NOT NULL,
	[Category17] [char](30) NOT NULL,
	[Category18Code] [char](3) NOT NULL,
	[Category18] [char](30) NOT NULL,
	[Category19Code] [char](3) NOT NULL,
	[Category19] [char](30) NOT NULL,
	[Category20Code] [char](3) NOT NULL,
	[Category20] [char](30) NOT NULL,
	[Category21Code] [char](3) NOT NULL,
	[Category21] [char](30) NOT NULL,
	[Category22Code] [char](3) NOT NULL,
	[Category22] [char](30) NOT NULL,
	[Category23Code] [char](3) NOT NULL,
	[Category23] [char](30) NOT NULL,
	[Category24Code] [char](3) NOT NULL,
	[Category24] [char](30) NOT NULL,
	[Category25Code] [char](3) NOT NULL,
	[Category25] [char](30) NOT NULL,
	[Category26Code] [char](3) NOT NULL,
	[Category26] [char](30) NOT NULL,
	[Category27Code] [char](3) NOT NULL,
	[Category27] [char](30) NOT NULL,
	[Category28Code] [char](3) NOT NULL,
	[Category28] [char](30) NOT NULL,
	[Category29Code] [char](3) NOT NULL,
	[Category29] [char](30) NOT NULL,
	[Category30Code] [char](3) NOT NULL,
	[Category30] [char](30) NOT NULL,
	[GLBankAccount] [char](8) NOT NULL,
	[TimeScheduledIn] [int] NOT NULL,
	[DateScheduledIn] [datetime] NOT NULL,
	[MessageClearedYN] [char](1) NOT NULL,
	[Remark] [char](30) NOT NULL,
	[Certificate] [char](20) NOT NULL,
	[EuropeanIndividualTaxID] [char](20) NOT NULL,
	[SecondaryAlphaName] [char](40) NOT NULL,
	[UserReservedCode] [char](2) NOT NULL,
	[UserReservedDate] [datetime] NOT NULL,
	[UserReservedAmount] [decimal](20, 7) NOT NULL,
	[UserReservedNumber] [int] NOT NULL,
	[UserReservedReference] [char](15) NOT NULL,
	[UserID] [char](10) NOT NULL,
	[ProgramID] [char](10) NOT NULL,
	[DateUpdated] [datetime] NOT NULL,
	[WorkStationID] [char](10) NOT NULL,
	[PurgeFlag] [char](1) NOT NULL,
	[ShortcutClientType] [char](2) NOT NULL,
	[LastTimeUpdated] [int] NOT NULL,
	[Ticker] [char](10) NOT NULL,
	[StockExchange] [char](10) NOT NULL,
	[DUNSNumber] [char](13) NOT NULL,
	[Classification01Code] [char](3) NOT NULL,
	[Classification01] [char](30) NOT NULL,
	[Classification02Code] [char](3) NOT NULL,
	[Classification02] [char](30) NOT NULL,
	[Classification03Code] [char](3) NOT NULL,
	[Classification03] [char](30) NOT NULL,
	[Classification04Code] [char](3) NOT NULL,
	[Classification04] [char](30) NOT NULL,
	[Classification05Code] [char](3) NOT NULL,
	[Classification05] [char](30) NOT NULL,
	[NumberOfEmployees] [int] NOT NULL,
	[GrowthRate] [int] NOT NULL,
	[YearStarted] [char](15) NOT NULL,
	[EmployeeGroupApprovals] [char](5) NOT NULL,
	[FutureUseIndicator] [char](1) NOT NULL,
	[RevenueRange] [char](5) NOT NULL,
	[SynchronizationStatus] [int] NOT NULL,
	[PreviousErrorStatus] [int] NOT NULL,
	[ServerStatus] [int] NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_Star_AddressBook] PRIMARY KEY CLUSTERED 
(
	[AddressNumber] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_BusinessUnit]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_BusinessUnit]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_BusinessUnit](
	[BusinessUnitID] [char](20) NOT NULL,
	[SourceID] [int] NOT NULL,
	[BusinessUnitCode] [char](12) NOT NULL,
	[Type] [char](2) NOT NULL,
	[BusinessUnitTypeDescription] [char](30) NOT NULL,
	[BusinessUnit] [char](30) NOT NULL,
	[PostingEditCode] [char](1) NOT NULL,
	[PostingEditCodeDescription] [char](30) NOT NULL,
	[CompanyNumber] [char](5) NOT NULL,
	[AddressNumber] [int] NOT NULL,
	[Category01Code] [char](3) NOT NULL,
	[Category01] [varchar](255) NOT NULL,
	[Category02Code] [char](3) NOT NULL,
	[Category02] [varchar](255) NOT NULL,
	[Category03Code] [char](3) NOT NULL,
	[Category03] [varchar](255) NOT NULL,
	[Category04Code] [char](3) NOT NULL,
	[Category04] [varchar](255) NOT NULL,
	[Category05Code] [char](3) NOT NULL,
	[Category05] [varchar](255) NOT NULL,
	[Category06Code] [char](3) NOT NULL,
	[Category06] [varchar](255) NOT NULL,
	[Category07Code] [char](3) NOT NULL,
	[Category07] [varchar](255) NOT NULL,
	[Category08Code] [char](3) NOT NULL,
	[Category08] [varchar](255) NOT NULL,
	[Category09Code] [char](3) NOT NULL,
	[Category09] [varchar](255) NOT NULL,
	[Category10Code] [char](3) NOT NULL,
	[Category10] [varchar](255) NOT NULL,
	[Category11Code] [char](3) NOT NULL,
	[Category11] [varchar](255) NOT NULL,
	[Category12Code] [char](3) NOT NULL,
	[Category12] [varchar](255) NOT NULL,
	[Category13Code] [char](3) NOT NULL,
	[Category13] [varchar](255) NOT NULL,
	[Category14Code] [char](3) NOT NULL,
	[Category14] [varchar](255) NOT NULL,
	[Category15Code] [char](3) NOT NULL,
	[Category15] [varchar](255) NOT NULL,
	[Category16Code] [char](3) NOT NULL,
	[Category16] [varchar](255) NOT NULL,
	[Category17Code] [char](3) NOT NULL,
	[Category17] [varchar](255) NOT NULL,
	[Category18Code] [char](3) NOT NULL,
	[Category18] [varchar](255) NOT NULL,
	[Category19Code] [char](3) NOT NULL,
	[Category19] [varchar](255) NOT NULL,
	[Category20Code] [char](3) NOT NULL,
	[Category20] [varchar](255) NOT NULL,
	[Category21Code] [char](10) NOT NULL,
	[Category21] [varchar](255) NOT NULL,
	[Category22Code] [char](10) NOT NULL,
	[Category22] [varchar](255) NOT NULL,
	[Category23Code] [char](10) NOT NULL,
	[Category23] [varchar](255) NOT NULL,
	[Category24Code] [char](10) NOT NULL,
	[Category24] [varchar](255) NOT NULL,
	[Category25Code] [char](10) NOT NULL,
	[Category25] [varchar](255) NOT NULL,
	[Category26Code] [char](10) NOT NULL,
	[Category26] [varchar](255) NOT NULL,
	[Category27Code] [char](10) NOT NULL,
	[Category27] [varchar](255) NOT NULL,
	[Category28Code] [char](10) NOT NULL,
	[Category28] [varchar](255) NOT NULL,
	[Category29Code] [char](10) NOT NULL,
	[Category29] [varchar](255) NOT NULL,
	[Category30Code] [char](10) NOT NULL,
	[Category30] [varchar](255) NOT NULL,
	[Source] [char](20) NOT NULL,
	[OwnerReceivableAddress] [int] NOT NULL,
	[County] [char](3) NOT NULL,
	[StateCode] [char](3) NOT NULL,
	[StateCodeDescription] [char](30) NOT NULL,
	[ContractType] [char](4) NOT NULL,
	[CertifiedJobYN] [char](1) NOT NULL,
	[ProjectNumber] [char](12) NOT NULL,
	[PercentComplete] [decimal](20, 7) NOT NULL,
	[CostToComplete] [decimal](20, 7) NOT NULL,
	[PlannedStartDateID] [bigint] NOT NULL,
	[ActualStartDateID] [bigint] NOT NULL,
	[PlannedCompletionDateID] [bigint] NOT NULL,
	[ActualCompletionDateID] [bigint] NOT NULL,
	[FinalPaymentDateID] [bigint] NOT NULL,
	[CostAtCompletion] [decimal](20, 7) NOT NULL,
	[ProfitAtCompletion] [decimal](20, 7) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_Star_BusinessUnit] PRIMARY KEY CLUSTERED 
(
	[BusinessUnitCode] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_Company]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_Company]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_Company](
	[CompanyNumberID] [bigint] NOT NULL,
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[CompanyNumber] [char](5) NOT NULL,
	[CompanyName] [char](30) NOT NULL,
	[CompanyLevel01Code] [char](3) NOT NULL,
	[CompanyLevel01] [varchar](255) NOT NULL,
	[CompanyLevel02Code] [char](3) NOT NULL,
	[CompanyLevel02] [varchar](255) NOT NULL,
	[CompanyLevel03Code] [char](3) NOT NULL,
	[CompanyLevel03] [varchar](255) NOT NULL,
	[CompanyLevel04Code] [char](3) NOT NULL,
	[CompanyLevel04] [varchar](255) NOT NULL,
	[CompanyLevel05Code] [char](3) NOT NULL,
	[CompanyLevel05] [varchar](255) NOT NULL,
	[CompanyLevel06Code] [char](3) NOT NULL,
	[CompanyLevel06] [varchar](255) NOT NULL,
	[CompanyLevel07Code] [char](3) NOT NULL,
	[CompanyLevel07] [varchar](255) NOT NULL,
	[CompanyLevel08Code] [char](3) NOT NULL,
	[CompanyLevel08] [varchar](255) NOT NULL,
	[CompanyLevel09Code] [char](3) NOT NULL,
	[CompanyLevel09] [varchar](255) NOT NULL,
	[CompanyLevel10Code] [char](3) NOT NULL,
	[CompanyLevel10] [varchar](255) NOT NULL,
	[CompanyLevel11Code] [char](3) NOT NULL,
	[CompanyLevel11] [varchar](255) NOT NULL,
	[CompanyLevel12Code] [char](3) NOT NULL,
	[CompanyLevel12] [varchar](255) NOT NULL,
	[CompanyLevel13Code] [char](3) NOT NULL,
	[CompanyLevel13] [varchar](255) NOT NULL,
	[CompanyLevel14Code] [char](3) NOT NULL,
	[CompanyLevel14] [varchar](255) NOT NULL,
	[CompanyLevel15Code] [char](3) NOT NULL,
	[CompanyLevel15] [varchar](255) NOT NULL,
	[CompanyLevel16Code] [char](3) NOT NULL,
	[CompanyLevel16] [varchar](255) NOT NULL,
	[CompanyLevel17Code] [char](3) NOT NULL,
	[CompanyLevel17] [varchar](255) NOT NULL,
	[CompanyLevel18Code] [char](3) NOT NULL,
	[CompanyLevel18] [varchar](255) NOT NULL,
	[CompanyLevel19Code] [char](3) NOT NULL,
	[CompanyLevel19] [varchar](255) NOT NULL,
	[CompanyLevel20Code] [char](3) NOT NULL,
	[CompanyLevel20] [varchar](255) NOT NULL,
	[CompanyLevel21Code] [char](10) NOT NULL,
	[CompanyLevel21] [varchar](255) NOT NULL,
	[CompanyLevel22Code] [char](10) NOT NULL,
	[CompanyLevel22] [varchar](255) NOT NULL,
	[CompanyLevel23Code] [char](10) NOT NULL,
	[CompanyLevel23] [varchar](255) NOT NULL,
	[CompanyLevel24Code] [char](10) NOT NULL,
	[CompanyLevel24] [varchar](255) NOT NULL,
	[CompanyLevel25Code] [char](10) NOT NULL,
	[CompanyLevel25] [varchar](255) NOT NULL,
	[CompanyLevel26Code] [char](10) NOT NULL,
	[CompanyLevel26] [varchar](255) NOT NULL,
	[CompanyLevel27Code] [char](10) NOT NULL,
	[CompanyLevel27] [varchar](255) NOT NULL,
	[CompanyLevel28Code] [char](10) NOT NULL,
	[CompanyLevel28] [varchar](255) NOT NULL,
	[CompanyLevel29Code] [char](10) NOT NULL,
	[CompanyLevel29] [varchar](255) NOT NULL,
	[CompanyLevel30Code] [char](10) NOT NULL,
	[CompanyLevel30] [varchar](255) NOT NULL,
	[FinancialReportingPeriod] [int] NOT NULL,
	[FinancialReportingYear] [int] NOT NULL,
	[CurrencyCode] [char](3) NOT NULL,
	[CurrentPeriodNumber] [int] NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_Star_Company] PRIMARY KEY CLUSTERED 
(
	[CompanyNumber] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_Cost]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_Cost]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_Cost](
	[CostID] [char](30) NOT NULL,
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[ItemNumber] [int] NOT NULL,
	[ItemNumber02] [char](25) NOT NULL,
	[ItemNumber03] [char](25) NOT NULL,
	[BusinessUnitCode] [char](12) NOT NULL,
	[Location] [char](20) NOT NULL,
	[LotNumber] [char](30) NOT NULL,
	[LotGrade] [char](3) NOT NULL,
	[CostMethodCode] [char](2) NOT NULL,
	[UnitCost] [decimal](20, 7) NOT NULL,
	[PurchasingCostingSelection] [char](1) NOT NULL,
	[InventoryCostingSelection] [char](1) NOT NULL,
	[UserReservedCode] [char](2) NOT NULL,
	[UserReservedDate] [datetime] NOT NULL,
	[UserReservedAmount] [decimal](20, 7) NOT NULL,
	[UserReservedNumber] [int] NOT NULL,
	[UserReservedReference] [char](15) NOT NULL,
	[UserID] [char](10) NOT NULL,
	[ProgramID] [char](10) NOT NULL,
	[WorkStationID] [char](10) NOT NULL,
	[DateUpdated] [datetime] NOT NULL,
	[TimeOfDay] [int] NOT NULL,
	[CostChangedFlag] [char](2) NOT NULL,
	[CarryingCost] [int] NOT NULL,
	[OverstockCost] [int] NOT NULL,
	[StockoutCost] [int] NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_Star_Cost] PRIMARY KEY CLUSTERED 
(
	[ItemNumber] ASC,
	[BusinessUnitCode] ASC,
	[Location] ASC,
	[LotNumber] ASC,
	[CostMethodCode] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_Dates]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_Dates]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_Dates](
	[Dates] [datetime] NOT NULL,
	[CalendarYear] [char](4) NOT NULL,
	[CalendarQuarter] [char](2) NOT NULL,
	[CalendarMonth] [char](2) NOT NULL,
	[CalendarMonthName] [char](10) NOT NULL,
	[CalendarMonthNameShort] [char](3) NOT NULL,
	[CalendarWeek] [char](2) NOT NULL,
	[CalendarDateWeekBegins] [datetime] NOT NULL,
	[CalendarJulian] [int] NOT NULL,
	[BalanceSheet] [char](24) NOT NULL,
	[IncomeSheet] [char](40) NOT NULL,
	[FiscalYear] [char](4) NOT NULL,
	[FiscalQuarter] [char](2) NOT NULL,
	[FiscalMonth] [char](2) NOT NULL,
	[FiscalMonthName] [char](10) NOT NULL,
	[FiscalMonthNameShort] [char](3) NOT NULL,
	[FiscalWeek] [char](2) NOT NULL,
	[FiscalDateWeekBegins] [datetime] NOT NULL,
	[FiscalJulian] [int] NOT NULL,
	[FiscalBalanceSheet] [char](24) NOT NULL,
	[FiscalIncomeSheet] [char](40) NOT NULL,
	[EndOfFiscalPeriod] [datetime] NOT NULL,
	[DayOfWeekNumber] [char](1) NOT NULL,
	[DayOfWeek] [char](10) NOT NULL,
	[DayOfWeekShort] [char](3) NOT NULL,
	[APAging] [char](10) NOT NULL,
	[ARAging] [char](10) NOT NULL,
	[DateID] [int] NOT NULL,
	[WorkDay] [int] NOT NULL,
	[WorkDayInMonth] [int] NOT NULL,
	[WorkDaysInMonth] [int] NOT NULL,
	[SalesDay] [int] NOT NULL,
	[SalesDayInMonth] [int] NOT NULL,
	[SalesDaysInMonth] [int] NOT NULL,
	[CalendarRollingDay] [int] NOT NULL,
	[FiscalRollingDay] [int] NOT NULL,
	[CalendarRollingWeek] [int] NOT NULL,
	[FiscalRollingWeek] [int] NOT NULL,
	[CalendarRollingMonth] [int] NOT NULL,
	[FiscalRollingMonth] [int] NOT NULL,
	[CalendarRollingQuarter] [int] NOT NULL,
	[FiscalRollingQuarter] [int] NOT NULL,
	[CalendarRollingYear] [int] NOT NULL,
	[FiscalRollingYear] [int] NOT NULL,
	[CorporateYear] [char](4) NOT NULL,
	[CorporateQuarter] [char](2) NOT NULL,
	[CorporateMonth] [char](2) NOT NULL,
	[CorporateMonthName] [char](10) NOT NULL,
	[CorporateMonthNameShort] [char](3) NOT NULL,
	[CorporateWeek] [char](2) NOT NULL,
	[CorporateWeekBegins] [datetime] NOT NULL,
	[CorporateBalanceSheet] [char](24) NOT NULL,
	[CorporateIncomeSheet] [char](40) NOT NULL,
	[EndOfCorporatePeriod] [datetime] NOT NULL,
	[FiscalDatePattern] [char](1) NOT NULL,
	[CompanyNumber] [char](5) NOT NULL,
	[CompanyDateID] [bigint] NOT NULL,
 CONSTRAINT [PK_DATESPattern] PRIMARY KEY CLUSTERED 
(
	[CompanyDateID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_DatesPeriod]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_DatesPeriod]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_DatesPeriod](
	[PeriodID] [bigint] NOT NULL,
	[CompanyNumber] [char](5) NOT NULL,
	[LocalYear] [char](4) NOT NULL,
	[LocalPeriod] [char](2) NOT NULL,
	[CorporateYear] [char](4) NOT NULL,
	[CorporatePeriod] [char](2) NOT NULL,
	[CalPer] [char](3) NOT NULL,
 CONSTRAINT [PK_DatesPeriod] PRIMARY KEY CLUSTERED 
(
	[PeriodID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_Employee]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_Employee]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_Employee](
	[EmployeeNumberID] [bigint] NOT NULL,
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[EmployeeNumber] [int] NOT NULL,
	[LongAddressNumber] [char](20) NOT NULL,
	[EmployeeName] [char](40) NOT NULL,
	[EmployeeSearchTypeCode] [char](3) NOT NULL,
	[EmployeeSearchType] [char](30) NOT NULL,
	[Category01Code] [char](3) NOT NULL,
	[Category01] [varchar](255) NOT NULL,
	[Category02Code] [char](3) NOT NULL,
	[Category02] [varchar](255) NOT NULL,
	[Category03Code] [char](3) NOT NULL,
	[Category03] [varchar](255) NOT NULL,
	[Category04Code] [char](3) NOT NULL,
	[Category04] [varchar](255) NOT NULL,
	[Category05Code] [char](3) NOT NULL,
	[Category05] [varchar](255) NOT NULL,
	[Category06Code] [char](3) NOT NULL,
	[Category06] [varchar](255) NOT NULL,
	[Category07Code] [char](3) NOT NULL,
	[Category07] [varchar](255) NOT NULL,
	[Category08Code] [char](3) NOT NULL,
	[Category08] [varchar](255) NOT NULL,
	[Category09Code] [char](3) NOT NULL,
	[Category09] [varchar](255) NOT NULL,
	[Category10Code] [char](3) NOT NULL,
	[Category10] [varchar](255) NOT NULL,
	[Category11Code] [char](3) NOT NULL,
	[Category11] [varchar](255) NOT NULL,
	[Category12Code] [char](3) NOT NULL,
	[Category12] [varchar](255) NOT NULL,
	[Category13Code] [char](3) NOT NULL,
	[Category13] [varchar](255) NOT NULL,
	[Category14Code] [char](3) NOT NULL,
	[Category14] [varchar](255) NOT NULL,
	[Category15Code] [char](3) NOT NULL,
	[Category15] [varchar](255) NOT NULL,
	[Category16Code] [char](3) NOT NULL,
	[Category16] [varchar](255) NOT NULL,
	[Category17Code] [char](3) NOT NULL,
	[Category17] [varchar](255) NOT NULL,
	[Category18Code] [char](3) NOT NULL,
	[Category18] [varchar](255) NOT NULL,
	[Category19Code] [char](3) NOT NULL,
	[Category19] [varchar](255) NOT NULL,
	[Category20Code] [char](3) NOT NULL,
	[Category20] [varchar](255) NOT NULL,
	[Category21Code] [char](3) NOT NULL,
	[Category21] [varchar](255) NOT NULL,
	[Category22Code] [char](3) NOT NULL,
	[Category22] [varchar](255) NOT NULL,
	[Category23Code] [char](3) NOT NULL,
	[Category23] [varchar](255) NOT NULL,
	[Category24Code] [char](3) NOT NULL,
	[Category24] [varchar](255) NOT NULL,
	[Category25Code] [char](3) NOT NULL,
	[Category25] [varchar](255) NOT NULL,
	[Category26Code] [char](3) NOT NULL,
	[Category26] [varchar](255) NOT NULL,
	[Category27Code] [char](3) NOT NULL,
	[Category27] [varchar](255) NOT NULL,
	[Category28Code] [char](3) NOT NULL,
	[Category28] [varchar](255) NOT NULL,
	[Category29Code] [char](3) NOT NULL,
	[Category29] [varchar](255) NOT NULL,
	[Category30Code] [char](3) NOT NULL,
	[Category30] [varchar](255) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_Star_Employee] PRIMARY KEY CLUSTERED 
(
	[EmployeeNumber] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_Employee_Tiers]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_Employee_Tiers]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_Employee_Tiers](
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[SupervisorTierLevel] [int] NOT NULL,
	[SupervisorTierDescription] [char](40) NOT NULL,
	[Supervisor] [char](30) NOT NULL,
	[SupervisorAddressNumber] [int] NOT NULL,
	[EmployeeTierLevel] [int] NOT NULL,
	[EmployeeTierDescription] [char](40) NOT NULL,
	[Employee] [char](30) NOT NULL,
	[EmployeeAddressNumber] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
 CONSTRAINT [PK_Star_Employee_Tiers] PRIMARY KEY CLUSTERED 
(
	[EmployeeAddressNumber] ASC,
	[SupervisorAddressNumber] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_FiscalYear]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_FiscalYear]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_FiscalYear](
	[FiscalYearID] [bigint] NOT NULL,
	[SourceID] [int] NOT NULL,
	[FiscalDatePattern] [char](1) NOT NULL,
	[FiscalYear] [int] NOT NULL,
	[FiscalYearchar] [char](4) NOT NULL,
	[DateFiscalYearBegins] [datetime] NOT NULL,
	[EndOfPeriod01] [datetime] NOT NULL,
	[EndOfPeriod02] [datetime] NOT NULL,
	[EndOfPeriod03] [datetime] NOT NULL,
	[EndOfPeriod04] [datetime] NOT NULL,
	[EndOfPeriod05] [datetime] NOT NULL,
	[EndOfPeriod06] [datetime] NOT NULL,
	[EndOfPeriod07] [datetime] NOT NULL,
	[EndOfPeriod08] [datetime] NOT NULL,
	[EndOfPeriod09] [datetime] NOT NULL,
	[EndOfPeriod10] [datetime] NOT NULL,
	[EndOfPeriod11] [datetime] NOT NULL,
	[EndOfPeriod12] [datetime] NOT NULL,
	[EndOfPeriod13] [datetime] NOT NULL,
	[EndOfPeriod14] [datetime] NOT NULL,
	[Source] [char](20) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_Star_FiscalYear] PRIMARY KEY CLUSTERED 
(
	[FiscalDatePattern] ASC,
	[FiscalYear] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_Item]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_Item]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_Item](
	[ItemNumberID] [bigint] NOT NULL,
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[ItemNumber] [int] NOT NULL,
	[ItemNumber02] [char](25) NOT NULL,
	[ItemNumber03] [char](25) NOT NULL,
	[Description01] [char](30) NOT NULL,
	[Description02] [char](30) NOT NULL,
	[SalesCategory01Code] [char](6) NOT NULL,
	[SalesCategory01] [varchar](255) NOT NULL,
	[SalesCategory02Code] [char](6) NOT NULL,
	[SalesCategory02] [varchar](255) NOT NULL,
	[SalesCategory03Code] [char](6) NOT NULL,
	[SalesCategory03] [varchar](255) NOT NULL,
	[SalesCategory04Code] [char](6) NOT NULL,
	[SalesCategory04] [varchar](255) NOT NULL,
	[SalesCategory05Code] [char](6) NOT NULL,
	[SalesCategory05] [varchar](255) NOT NULL,
	[SalesCategory06Code] [char](6) NOT NULL,
	[SalesCategory06] [varchar](255) NOT NULL,
	[SalesCategory07Code] [char](6) NOT NULL,
	[SalesCategory07] [varchar](255) NOT NULL,
	[SalesCategory08Code] [char](6) NOT NULL,
	[SalesCategory08] [varchar](255) NOT NULL,
	[SalesCategory09Code] [char](6) NOT NULL,
	[SalesCategory09] [varchar](255) NOT NULL,
	[SalesCategory10Code] [char](6) NOT NULL,
	[SalesCategory10] [varchar](255) NOT NULL,
	[PurchasingCategory01Code] [char](6) NOT NULL,
	[PurchasingCategory01] [varchar](255) NOT NULL,
	[PurchasingCategory02Code] [char](6) NOT NULL,
	[PurchasingCategory02] [varchar](255) NOT NULL,
	[PurchasingCategory03Code] [char](6) NOT NULL,
	[PurchasingCategory03] [varchar](255) NOT NULL,
	[PurchasingCategory04Code] [char](6) NOT NULL,
	[PurchasingCategory04] [varchar](255) NOT NULL,
	[PurchasingCategory05Code] [char](6) NOT NULL,
	[PurchasingCategory05] [varchar](255) NOT NULL,
	[PurchasingCategory06Code] [char](6) NOT NULL,
	[PurchasingCategory06] [varchar](255) NOT NULL,
	[PurchasingCategory07Code] [char](6) NOT NULL,
	[PurchasingCategory07] [varchar](255) NOT NULL,
	[PurchasingCategory08Code] [char](6) NOT NULL,
	[PurchasingCategory08] [varchar](255) NOT NULL,
	[PurchasingCategory09Code] [char](6) NOT NULL,
	[PurchasingCategory09] [varchar](255) NOT NULL,
	[PurchasingCategory10Code] [char](6) NOT NULL,
	[PurchasingCategory10] [varchar](255) NOT NULL,
	[UnitOfMeasurePrimary] [char](2) NOT NULL,
	[UnitOfMeasureSecondary] [char](2) NOT NULL,
	[UnitOfMeasurePurchas] [char](2) NOT NULL,
	[UnitOfMeasurePricing] [char](2) NOT NULL,
	[UnitOfMeasureShipping] [char](2) NOT NULL,
	[UnitOfMeasureProduction] [char](2) NOT NULL,
	[UnitOfMeasureAllocation] [char](2) NOT NULL,
	[UnitOfMeasureWeight] [char](2) NOT NULL,
	[UOMVolume] [char](2) NOT NULL,
	[UOMStocking] [char](2) NOT NULL,
	[UOMVolumeOrWeightPSAU] [char](1) NOT NULL,
	[CycleCountCategory] [char](3) NOT NULL,
	[GLCategory] [char](4) NOT NULL,
	[ProductGroupCode] [char](3) NOT NULL,
	[ProductGroup] [char](30) NOT NULL,
	[ItemPriceGroupCode] [char](8) NOT NULL,
	[ItemPriceGroup] [char](30) NOT NULL,
	[StockingTypeCode] [char](1) NOT NULL,
	[StockingType] [char](30) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_Star_Item] PRIMARY KEY CLUSTERED 
(
	[ItemNumber] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_ItemBranch]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_ItemBranch]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_ItemBranch](
	[ItemBranchID] [char](30) NOT NULL,
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[ItemNumber] [int] NOT NULL,
	[ItemNumber02] [char](25) NOT NULL,
	[ItemNumber03] [char](25) NOT NULL,
	[BusinessUnitCode] [char](12) NOT NULL,
	[SalesCategory01Code] [char](6) NOT NULL,
	[SalesCategory01] [varchar](255) NOT NULL,
	[SalesCategory02Code] [char](6) NOT NULL,
	[SalesCategory02] [varchar](255) NOT NULL,
	[SalesCategory03Code] [char](6) NOT NULL,
	[SalesCategory03] [varchar](255) NOT NULL,
	[SalesCategory04Code] [char](6) NOT NULL,
	[SalesCategory04] [varchar](255) NOT NULL,
	[SalesCategory05Code] [char](6) NOT NULL,
	[SalesCategory05] [varchar](255) NOT NULL,
	[SalesCategory06Code] [char](6) NOT NULL,
	[SalesCategory06] [varchar](255) NOT NULL,
	[SalesCategory07Code] [char](6) NOT NULL,
	[SalesCategory07] [varchar](255) NOT NULL,
	[SalesCategory08Code] [char](6) NOT NULL,
	[SalesCategory08] [varchar](255) NOT NULL,
	[SalesCategory09Code] [char](6) NOT NULL,
	[SalesCategory09] [varchar](255) NOT NULL,
	[SalesCategory10Code] [char](6) NOT NULL,
	[SalesCategory10] [varchar](255) NOT NULL,
	[PurchasingCategory01Code] [char](6) NOT NULL,
	[PurchasingCategory01] [varchar](255) NOT NULL,
	[PurchasingCategory02Code] [char](6) NOT NULL,
	[PurchasingCategory02] [varchar](255) NOT NULL,
	[PurchasingCategory03Code] [char](6) NOT NULL,
	[PurchasingCategory03] [varchar](255) NOT NULL,
	[PurchasingCategory04Code] [char](6) NOT NULL,
	[PurchasingCategory04] [varchar](255) NOT NULL,
	[PurchasingCategory05Code] [char](6) NOT NULL,
	[PurchasingCategory05] [varchar](255) NOT NULL,
	[PurchasingCategory06Code] [char](6) NOT NULL,
	[PurchasingCategory06] [varchar](255) NOT NULL,
	[PurchasingCategory07Code] [char](6) NOT NULL,
	[PurchasingCategory07] [varchar](255) NOT NULL,
	[PurchasingCategory08Code] [char](6) NOT NULL,
	[PurchasingCategory08] [varchar](255) NOT NULL,
	[PurchasingCategory09Code] [char](6) NOT NULL,
	[PurchasingCategory09] [varchar](255) NOT NULL,
	[PurchasingCategory10Code] [char](6) NOT NULL,
	[PurchasingCategory10] [varchar](255) NOT NULL,
	[ProductGroupCode] [char](3) NOT NULL,
	[ProductGroup] [char](30) NOT NULL,
	[DispatchGroup] [char](3) NOT NULL,
	[PrimaryLastSupplierNumber] [int] NOT NULL,
	[PlannerNumber] [int] NOT NULL,
	[BuyerNumber] [int] NOT NULL,
	[GLCategory] [char](4) NOT NULL,
	[CountryofOrigin] [char](3) NOT NULL,
	[ReorderPoint] [decimal](22, 7) NOT NULL,
	[ReorderQuantity] [decimal](22, 7) NOT NULL,
	[MaximumReorderQuantity] [decimal](22, 7) NOT NULL,
	[MinimumReorderQuantity] [decimal](22, 7) NOT NULL,
	[MultipleOrderQuantitySoPo] [decimal](22, 7) NOT NULL,
	[ServiceLevel] [decimal](22, 7) NOT NULL,
	[SafetyStock] [decimal](22, 7) NOT NULL,
	[ShelfLifeDays] [int] NOT NULL,
	[CheckAvailability] [char](1) NOT NULL,
	[LayerCodeSource] [char](1) NOT NULL,
	[LotStatusCode] [char](1) NOT NULL,
	[PotencyControl] [char](1) NOT NULL,
	[GradeControl] [char](1) NOT NULL,
	[StandardPotency] [decimal](20, 7) NOT NULL,
	[FromPotency] [decimal](20, 7) NOT NULL,
	[ThruPotency] [decimal](20, 7) NOT NULL,
	[StandardGrade] [char](3) NOT NULL,
	[FromGrade] [char](3) NOT NULL,
	[ThruGrade] [char](3) NOT NULL,
	[ComponentType] [char](1) NOT NULL,
	[MarginMaintenance] [decimal](20, 7) NOT NULL,
	[ItemPriceGroupCode] [char](8) NOT NULL,
	[ItemPriceGroup] [char](30) NOT NULL,
	[BasketRepriceGroup] [char](8) NOT NULL,
	[OrderRepriceGroup] [char](8) NOT NULL,
	[BackOrdersAllowed] [char](10) NOT NULL,
	[ItemFlashMessage] [char](2) NOT NULL,
	[TempFlashMessage] [char](2) NOT NULL,
	[ABCCode1Sales] [char](1) NOT NULL,
	[ABCCode2Margin] [char](1) NOT NULL,
	[ABCCode3Investment] [char](1) NOT NULL,
	[ABCCodeOverrideIndicator] [char](1) NOT NULL,
	[ShippingCommodityClass] [char](3) NOT NULL,
	[PreferredCarrierSales] [int] NOT NULL,
	[PreferredCarrierPurchasing] [int] NOT NULL,
	[ShippingConditionsCode] [char](3) NOT NULL,
	[StockingTypeCode] [char](1) NOT NULL,
	[StockingType] [char](30) NOT NULL,
	[LineType] [char](2) NOT NULL,
	[FIFOProcessing] [char](10) NOT NULL,
	[CycleCountCategory] [char](3) NOT NULL,
	[PrintMessage] [char](10) NOT NULL,
	[TypeWarranty] [char](8) NOT NULL,
	[SerialNumberRequired] [char](1) NOT NULL,
	[PercentMargin] [decimal](20, 7) NOT NULL,
	[CommissionCategory] [char](8) NOT NULL,
	[ApplyFreight] [char](1) NOT NULL,
	[Taxable] [char](1) NOT NULL,
	[SalesTaxable] [char](1) NOT NULL,
	[PlanningCode] [char](1) NOT NULL,
	[ItemDisplayCode] [char](1) NOT NULL,
	[NetChangeFlag] [char](1) NOT NULL,
	[UnitsPerContainer] [decimal](22, 7) NOT NULL,
	[RoundToWholeNumber] [char](10) NOT NULL,
	[ItemRevisionLevel] [char](3) NOT NULL,
	[LeadtimeLevel] [int] NOT NULL,
	[LeadtimeManufacturing] [int] NOT NULL,
	[LeadtimeCumulative] [int] NOT NULL,
	[OrderPolicyCode] [char](1) NOT NULL,
	[ValueOrderPolicy] [decimal](15, 0) NOT NULL,
	[AccountingCostQuantity] [decimal](22, 7) NOT NULL,
	[MFGLeadtimeQuantity] [decimal](22, 7) NOT NULL,
	[LeadtimePerUnit] [numeric](20, 7) NOT NULL,
	[PlanningFenceRule] [char](1) NOT NULL,
	[FixedVariableLeadtime] [char](1) NOT NULL,
	[IssueTypeCode] [char](1) NOT NULL,
	[ECONumber] [char](12) NOT NULL,
	[ECOReason] [char](2) NOT NULL,
	[EngineeringChangeDate] [datetime] NOT NULL,
	[FreezeFence] [int] NOT NULL,
	[MessageDisplayFence] [int] NOT NULL,
	[TimeFence] [int] NOT NULL,
	[ShipmentLeadtimeOffset] [int] NOT NULL,
	[MoveHours] [decimal](20, 7) NOT NULL,
	[QueueHours] [decimal](20, 7) NOT NULL,
	[StandardSetupHours] [decimal](20, 7) NOT NULL,
	[ShrinkFactor] [decimal](20, 7) NOT NULL,
	[ShrinkFactorMethod] [char](1) NOT NULL,
	[TimeBasis] [char](1) NOT NULL,
	[BatchQuantity] [decimal](22, 7) NOT NULL,
	[OrderWith] [char](1) NOT NULL,
	[ExpediteDamperDays] [int] NOT NULL,
	[DeferDamperDays] [int] NOT NULL,
	[MultipleOrderQuantityMRP] [decimal](22, 7) NOT NULL,
	[SafetyLeadtime] [int] NOT NULL,
	[MakeBuyCode] [char](1) NOT NULL,
	[DateFutureUse] [datetime] NOT NULL,
	[LowLevelCode] [int] NOT NULL,
	[CommitmentMethod] [char](1) NOT NULL,
	[SpecificCommitmentDays] [int] NOT NULL,
	[UserReservedCode] [char](2) NOT NULL,
	[UserReservedDate] [datetime] NOT NULL,
	[UserReservedAmount] [decimal](20, 7) NOT NULL,
	[UserReservedNumber] [int] NOT NULL,
	[UserReservedReference] [char](15) NOT NULL,
	[UserID] [char](10) NOT NULL,
	[ProgramID] [char](10) NOT NULL,
	[WorkStationID] [char](10) NOT NULL,
	[DateUpdated] [datetime] NOT NULL,
	[TimeOfDay] [int] NOT NULL,
	[CommodityCode] [char](15) NOT NULL,
	[PlanningFence] [int] NOT NULL,
	[AddressNumber] [numeric](8, 0) NOT NULL,
	[BranchPlantDescription] [char](40) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_Star_ItemBranch] PRIMARY KEY CLUSTERED 
(
	[ItemNumber] ASC,
	[BusinessUnitCode] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_PaymentTerms]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_PaymentTerms]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_PaymentTerms](
	[PaymentTermID] [char](20) NOT NULL,
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[PaymentTerms] [char](3) NOT NULL,
	[Description] [char](30) NOT NULL,
	[DiscountPercent] [decimal](15, 5) NOT NULL,
	[DiscountDays] [int] NOT NULL,
	[NetDaysToPay] [int] NOT NULL,
	[DueDate] [datetime] NOT NULL,
	[NumberOfSplitPayments] [int] NOT NULL,
	[DaysToPayAging] [int] NOT NULL,
	[EffectiveInterestRate] [decimal](15, 3) NOT NULL,
	[ProxDateMonth] [int] NOT NULL,
	[ProxDateDay] [int] NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_Star_PaymentTerms] PRIMARY KEY CLUSTERED 
(
	[PaymentTerms] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_Price]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_Price]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_Price](
	[PriceID] [char](30) NOT NULL,
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[ItemNumber] [int] NOT NULL,
	[ItemNumber02] [char](25) NOT NULL,
	[ItemNumber03] [char](25) NOT NULL,
	[BusinessUnitCode] [char](12) NOT NULL,
	[Location] [char](20) NOT NULL,
	[LotNumber] [char](30) NOT NULL,
	[AddressNumber] [int] NOT NULL,
	[ItemCustomerKeyID] [int] NOT NULL,
	[LotGrade] [char](3) NOT NULL,
	[FromPotency] [decimal](20, 7) NOT NULL,
	[CurrencyCode] [char](3) NOT NULL,
	[UnitOfMeasureAsInput] [char](2) NOT NULL,
	[EffectiveDate] [datetime] NOT NULL,
	[ExpiredDate] [datetime] NOT NULL,
	[UnitPrice] [decimal](20, 7) NOT NULL,
	[CreditPrice] [decimal](20, 7) NOT NULL,
	[Basis] [char](1) NOT NULL,
	[CostMethodCode] [char](2) NOT NULL,
	[CostMethod] [char](30) NOT NULL,
	[FactorValue] [decimal](20, 7) NOT NULL,
	[FormulaName] [char](10) NOT NULL,
	[UserReservedCode] [char](2) NOT NULL,
	[UserReservedDate] [datetime] NOT NULL,
	[UserReservedAmount] [decimal](20, 7) NOT NULL,
	[UserReservedNumber] [int] NOT NULL,
	[UserReservedReference] [char](15) NOT NULL,
	[UserID] [char](10) NOT NULL,
	[ProgramID] [char](10) NOT NULL,
	[WorkStationID] [char](10) NOT NULL,
	[DateUpdated] [datetime] NOT NULL,
	[TimeOfDay] [int] NOT NULL,
	[ItemGroupKeyID] [int] NOT NULL,
	[CustomerGroupKeyID] [int] NOT NULL,
	[ApprovalStatus] [char](2) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_Star_Price] PRIMARY KEY CLUSTERED 
(
	[SourceID] ASC,
	[ItemNumber] ASC,
	[BusinessUnitCode] ASC,
	[Location] ASC,
	[LotNumber] ASC,
	[AddressNumber] ASC,
	[LotGrade] ASC,
	[FromPotency] ASC,
	[CurrencyCode] ASC,
	[UnitOfMeasureAsInput] ASC,
	[ExpiredDate] ASC,
	[DateUpdated] ASC,
	[TimeOfDay] ASC,
	[ItemGroupKeyID] ASC,
	[CustomerGroupKeyID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_Supplier]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_Supplier]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_Supplier](
	[SupplierNumberID] [bigint] NOT NULL,
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[SupplierNumber] [int] NOT NULL,
	[SupplierName] [char](40) NOT NULL,
	[SupplierAddressLine01] [char](40) NOT NULL,
	[SupplierAddressLine02] [char](40) NOT NULL,
	[SupplierAddressLine03] [char](40) NOT NULL,
	[SupplierAddressLine04] [char](40) NOT NULL,
	[SupplierPostalCode] [char](12) NOT NULL,
	[SupplierCity] [char](25) NOT NULL,
	[SupplierCounty] [char](25) NOT NULL,
	[SupplierStateCode] [char](3) NOT NULL,
	[SupplierState] [char](30) NOT NULL,
	[SupplierCountry] [char](30) NOT NULL,
	[SupplierCountryCode] [char](3) NOT NULL,
	[ParentNumber] [int] NOT NULL,
	[ParentName] [char](40) NOT NULL,
	[ParentAddressLine01] [char](40) NOT NULL,
	[ParentAddressLine02] [char](40) NOT NULL,
	[ParentAddressLine03] [char](40) NOT NULL,
	[ParentAddressLine04] [char](40) NOT NULL,
	[ParentPostalCode] [char](12) NOT NULL,
	[ParentCity] [char](25) NOT NULL,
	[ParentCounty] [char](25) NOT NULL,
	[ParentStateCode] [char](3) NOT NULL,
	[ParentState] [char](30) NOT NULL,
	[ParentCountry] [char](30) NOT NULL,
	[ParentCountryCode] [char](3) NOT NULL,
	[SupplierParentRebatelevel] [char](1) NOT NULL,
	[SupplierRebateCode] [char](1) NOT NULL,
	[CustomerTypeIdentifier] [char](1) NOT NULL,
	[HoldOrdersCode] [char](2) NOT NULL,
	[RouteCode] [char](3) NOT NULL,
	[StopCode] [char](3) NOT NULL,
	[ZoneNumber] [char](3) NOT NULL,
	[CarrierCode] [int] NOT NULL,
	[GLClass] [char](4) NOT NULL,
	[PaymentInstrument] [char](1) NOT NULL,
	[ApproverNumber] [int] NOT NULL,
	[PaymentTermsAP] [char](3) NOT NULL,
	[PaymentTerms] [char](30) NOT NULL,
	[RelatedAddressNumber] [int] NOT NULL,
	[SearchTypeCode] [char](3) NOT NULL,
	[SearchType] [char](30) NOT NULL,
	[Category01Code] [char](3) NOT NULL,
	[Category01] [varchar](255) NOT NULL,
	[Category02Code] [char](3) NOT NULL,
	[Category02] [varchar](255) NOT NULL,
	[Category03Code] [char](3) NOT NULL,
	[Category03] [varchar](255) NOT NULL,
	[Category04Code] [char](3) NOT NULL,
	[Category04] [varchar](255) NOT NULL,
	[Category05Code] [char](3) NOT NULL,
	[Category05] [varchar](255) NOT NULL,
	[Category06Code] [char](3) NOT NULL,
	[Category06] [varchar](255) NOT NULL,
	[Category07Code] [char](3) NOT NULL,
	[Category07] [varchar](255) NOT NULL,
	[Category08Code] [char](3) NOT NULL,
	[Category08] [varchar](255) NOT NULL,
	[Category09Code] [char](3) NOT NULL,
	[Category09] [varchar](255) NOT NULL,
	[Category10Code] [char](3) NOT NULL,
	[Category10] [varchar](255) NOT NULL,
	[Category11Code] [char](3) NOT NULL,
	[Category11] [varchar](255) NOT NULL,
	[Category12Code] [char](3) NOT NULL,
	[Category12] [varchar](255) NOT NULL,
	[Category13Code] [char](3) NOT NULL,
	[Category13] [varchar](255) NOT NULL,
	[Category14Code] [char](3) NOT NULL,
	[Category14] [varchar](255) NOT NULL,
	[Category15Code] [char](3) NOT NULL,
	[Category15] [varchar](255) NOT NULL,
	[Category16Code] [char](3) NOT NULL,
	[Category16] [varchar](255) NOT NULL,
	[Category17Code] [char](3) NOT NULL,
	[Category17] [varchar](255) NOT NULL,
	[Category18Code] [char](3) NOT NULL,
	[Category18] [varchar](255) NOT NULL,
	[Category19Code] [char](3) NOT NULL,
	[Category19] [varchar](255) NOT NULL,
	[Category20Code] [char](3) NOT NULL,
	[Category20] [varchar](255) NOT NULL,
	[Category21Code] [char](10) NOT NULL,
	[Category21] [varchar](255) NOT NULL,
	[Category22Code] [char](10) NOT NULL,
	[Category22] [varchar](255) NOT NULL,
	[Category23Code] [char](10) NOT NULL,
	[Category23] [varchar](255) NOT NULL,
	[Category24Code] [char](10) NOT NULL,
	[Category24] [varchar](255) NOT NULL,
	[Category25Code] [char](10) NOT NULL,
	[Category25] [varchar](255) NOT NULL,
	[Category26Code] [char](10) NOT NULL,
	[Category26] [varchar](255) NOT NULL,
	[Category27Code] [char](10) NOT NULL,
	[Category27] [varchar](255) NOT NULL,
	[Category28Code] [char](10) NOT NULL,
	[Category28] [varchar](255) NOT NULL,
	[Category29Code] [char](10) NOT NULL,
	[Category29] [varchar](255) NOT NULL,
	[Category30Code] [char](10) NOT NULL,
	[Category30] [varchar](255) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_Star_Supplier] PRIMARY KEY CLUSTERED 
(
	[SupplierNumber] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_UOMConversionFactors]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_UOMConversionFactors]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_UOMConversionFactors](
	[SOURCE] [char](20) NOT NULL,
	[SourceID] [int] NOT NULL,
	[BusinessUnitCode] [char](12) NOT NULL,
	[ItemNumber] [int] NOT NULL,
	[UnitOfMeasure] [char](2) NOT NULL,
	[RelatedUnitOfMeasure] [char](2) NOT NULL,
	[UnitOfMeasureStructure] [char](1) NOT NULL,
	[ConversionFactor] [decimal](20, 7) NOT NULL,
	[ConvFactorSecondaryToPrimary] [decimal](20, 7) NOT NULL,
	[UserID] [char](10) NOT NULL,
	[ProgramID] [char](10) NOT NULL,
	[WorkStationID] [char](10) NOT NULL,
	[DateUpdated] [datetime] NOT NULL,
	[TimeOfDay] [int] NOT NULL,
	[ExcludefromPO] [char](2) NOT NULL,
	[ExcludefromSO] [char](2) NOT NULL,
	[CodePurchasePriceCode] [decimal](20, 7) NOT NULL,
	[CodeSalesPriceCode] [decimal](20, 7) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_Star_UOMConversionFactors] PRIMARY KEY CLUSTERED 
(
	[BusinessUnitCode] ASC,
	[ItemNumber] ASC,
	[UnitOfMeasure] ASC,
	[RelatedUnitOfMeasure] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Star_UOMConversionFactors_temp]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Star_UOMConversionFactors_temp]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Star_UOMConversionFactors_temp](
	[SOURCE] [char](20) NOT NULL,
	[SourceID] [int] NOT NULL,
	[BusinessUnitCode] [char](12) NOT NULL,
	[ItemNumber] [int] NOT NULL,
	[UnitOfMeasure] [char](2) NOT NULL,
	[RelatedUnitOfMeasure] [char](2) NOT NULL,
	[UnitOfMeasureStructure] [char](1) NOT NULL,
	[ConversionFactor] [decimal](20, 7) NOT NULL,
	[ConvFactorSecondaryToPrimary] [decimal](20, 7) NOT NULL,
	[UserID] [char](10) NOT NULL,
	[ProgramID] [char](10) NOT NULL,
	[WorkStationID] [char](10) NOT NULL,
	[DateUpdated] [datetime] NOT NULL,
	[TimeOfDay] [int] NOT NULL,
	[ExcludefromPO] [char](2) NOT NULL,
	[ExcludefromSO] [char](2) NOT NULL,
	[CodePurchasePriceCode] [decimal](20, 7) NOT NULL,
	[CodeSalesPriceCode] [decimal](20, 7) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_Star_UOMConversionFactors_temp] PRIMARY KEY CLUSTERED 
(
	[BusinessUnitCode] ASC,
	[ItemNumber] ASC,
	[UnitOfMeasure] ASC,
	[RelatedUnitOfMeasure] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80, DATA_COMPRESSION = PAGE) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TIER_HIERARCHY]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TIER_HIERARCHY]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TIER_HIERARCHY](
	[CURRENT_LEAF] [int] NULL,
	[LEAF_LEVEL] [int] NULL,
	[LEVEL0] [int] NULL,
	[LEVEL1] [int] NULL,
	[LEVEL2] [int] NULL,
	[LEVEL3] [int] NULL,
	[LEVEL4] [int] NULL,
	[LEVEL5] [int] NULL,
	[LEVEL6] [int] NULL,
	[LEVEL7] [int] NULL,
	[LEVEL8] [int] NULL,
	[LEVEL9] [int] NULL,
	[LEVEL10] [int] NULL
) ON [PRIMARY]
WITH
(
DATA_COMPRESSION = PAGE
)
END
GO
/****** Object:  Table [dbo].[TIER2]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TIER2]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TIER2](
	[CURRENT_LEAF_EMP] [int] NULL,
	[CURRENT_LEAF_TIERLEVEL] [int] NULL,
	[CURRENT_LEAF_TIERDESC] [varchar](40) NULL,
	[CURRENT_LEAF_EMPNAME] [varchar](40) NULL,
	[LEAF_LEVEL] [int] NULL,
	[LEVEL0_EMP] [int] NULL,
	[LEVEL0_TIERLEVEL] [int] NULL,
	[LEVEL0_TIERDESC] [varchar](40) NULL,
	[LEVEL0_EMPNAME] [varchar](40) NULL,
	[LEVEL1_EMP] [int] NULL,
	[LEVEL2_EMP] [int] NULL,
	[LEVEL3_EMP] [int] NULL,
	[LEVEL4_EMP] [int] NULL,
	[LEVEL5_EMP] [int] NULL,
	[LEVEL6_EMP] [int] NULL,
	[LEVEL7_EMP] [int] NULL,
	[LEVEL8_EMP] [int] NULL,
	[LEVEL9_EMP] [int] NULL,
	[LEVEL10_EMP] [int] NULL
) ON [PRIMARY]
WITH
(
DATA_COMPRESSION = PAGE
)
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  View [dbo].[duplicate_temp]    Script Date: 5/30/13 12:57:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[duplicate_temp]'))
EXEC dbo.sp_executesql @statement = N'CREATE  VIEW [dbo].[duplicate_temp]
AS

select businessunitcode,itemnumber,unitofmeasure,relatedunitofmeasure,count(*) cnt from dbo.Star_UOMConversionFactors
group by businessunitcode, itemnumber, unitofmeasure, relatedunitofmeasure
having count(*) > 1
' 
GO
/****** Object:  Index [PK_AR_Star_Customer]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AR_Star_Customer]') AND name = N'PK_AR_Star_Customer')
CREATE CLUSTERED INDEX [PK_AR_Star_Customer] ON [dbo].[AR_Star_Customer]
(
	[CustomerNumberID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, DATA_COMPRESSION = PAGE) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [PK_DeliveryCycle]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[DeliveryDayCodeDetails]') AND name = N'PK_DeliveryCycle')
CREATE UNIQUE CLUSTERED INDEX [PK_DeliveryCycle] ON [dbo].[DeliveryDayCodeDetails]
(
	[DeliveryCycle] ASC,
	[Frequency] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80, DATA_COMPRESSION = PAGE) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [PK_Contrain]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[MasterDeliveryDateCalendar]') AND name = N'PK_Contrain')
CREATE UNIQUE CLUSTERED INDEX [PK_Contrain] ON [dbo].[MasterDeliveryDateCalendar]
(
	[Delivery Date] ASC,
	[Delivery Cycle] ASC,
	[Date Of Week] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80, DATA_COMPRESSION = PAGE) ON [PRIMARY]
GO
/****** Object:  Index [IX_AR_Star_BillToNumber]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AR_Star_Customer]') AND name = N'IX_AR_Star_BillToNumber')
CREATE NONCLUSTERED INDEX [IX_AR_Star_BillToNumber] ON [dbo].[AR_Star_Customer]
(
	[BillToNumber] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [IX_AR_Star_Customer_BillTo_Company]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AR_Star_Customer]') AND name = N'IX_AR_Star_Customer_BillTo_Company')
CREATE NONCLUSTERED INDEX [IX_AR_Star_Customer_BillTo_Company] ON [dbo].[AR_Star_Customer]
(
	[BillToNumber] ASC,
	[CompanyNumber] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_AR_Star_Customer_CustomerNumberID]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AR_Star_Customer]') AND name = N'IX_AR_Star_Customer_CustomerNumberID')
CREATE NONCLUSTERED INDEX [IX_AR_Star_Customer_CustomerNumberID] ON [dbo].[AR_Star_Customer]
(
	[CustomerNumberID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_AR_Star_CustomerNumber]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AR_Star_Customer]') AND name = N'IX_AR_Star_CustomerNumber')
CREATE NONCLUSTERED INDEX [IX_AR_Star_CustomerNumber] ON [dbo].[AR_Star_Customer]
(
	[CustomerNumber] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [IX_AR_Star_ParentNumber]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AR_Star_Customer]') AND name = N'IX_AR_Star_ParentNumber')
CREATE NONCLUSTERED INDEX [IX_AR_Star_ParentNumber] ON [dbo].[AR_Star_Customer]
(
	[ParentNumber] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_487]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[AR_Star_Customer]') AND name = N'missing_index_487')
CREATE NONCLUSTERED INDEX [missing_index_487] ON [dbo].[AR_Star_Customer]
(
	[Category06Code] ASC
)
INCLUDE ( 	[CustomerNumberID],
	[BillToNumber],
	[BillToName],
	[RelatedAddressNumber],
	[Category03Code],
	[Category08Code]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [IX_index_MasterDeliveryDateCalendar_ychoi_040312]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[MasterDeliveryDateCalendar]') AND name = N'IX_index_MasterDeliveryDateCalendar_ychoi_040312')
CREATE NONCLUSTERED INDEX [IX_index_MasterDeliveryDateCalendar_ychoi_040312] ON [dbo].[MasterDeliveryDateCalendar]
(
	[Delivery Cycle] ASC
)
INCLUDE ( 	[Delivery Date]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [_dta_index_Sales_Star_Customer_11_659689598__K4_K2_K47_K1]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'_dta_index_Sales_Star_Customer_11_659689598__K4_K2_K47_K1')
CREATE NONCLUSTERED INDEX [_dta_index_Sales_Star_Customer_11_659689598__K4_K2_K47_K1] ON [dbo].[Sales_Star_Customer]
(
	[ParentNumber] ASC,
	[SourceID] ASC,
	[ShiptoNumber] ASC,
	[CustomerNumberID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [IX_index_Sales_Star_Customer_11_2_ychoi_040312]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'IX_index_Sales_Star_Customer_11_2_ychoi_040312')
CREATE NONCLUSTERED INDEX [IX_index_Sales_Star_Customer_11_2_ychoi_040312] ON [dbo].[Sales_Star_Customer]
(
	[Category06Code] ASC,
	[ShiptoSearchTypeCode] ASC,
	[CustomerNumberID] ASC,
	[SourceID] ASC,
	[ShiptoNumber] ASC,
	[ShiptoName] ASC,
	[Category03Code] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [IX_index_Sales_Star_Customer_11_3_ychoi_040312]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'IX_index_Sales_Star_Customer_11_3_ychoi_040312')
CREATE NONCLUSTERED INDEX [IX_index_Sales_Star_Customer_11_3_ychoi_040312] ON [dbo].[Sales_Star_Customer]
(
	[StopCode] ASC,
	[ShiptoSearchTypeCode] ASC,
	[Category06Code] ASC,
	[SourceID] ASC,
	[ShiptoNumber] ASC,
	[ShiptoName] ASC,
	[Category03Code] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [IX_index_Sales_Star_Customer_11_ychoi_040312]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'IX_index_Sales_Star_Customer_11_ychoi_040312')
CREATE NONCLUSTERED INDEX [IX_index_Sales_Star_Customer_11_ychoi_040312] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoSearchTypeCode] ASC,
	[LastInvoiceDate] ASC,
	[Category06Code] ASC,
	[ShiptoNumber] ASC,
	[ShiptoName] ASC,
	[Category03Code] ASC
)
WHERE ([Sales_Star_Customer].[ShiptoSearchTypeCode]<>'CCX' AND [Sales_Star_Customer].[ShiptoSearchTypeCode]<>'CFX' AND [Sales_Star_Customer].[ShiptoSearchTypeCode]<>'RP ' AND [Sales_Star_Customer].[ShiptoSearchTypeCode]<>'RT ' AND [Sales_Star_Customer].[ShiptoSearchTypeCode]<>'SP ' AND [Sales_Star_Customer].[Category06Code]='O00')
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [IX_Sales_Star_CompanyNumber]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'IX_Sales_Star_CompanyNumber')
CREATE NONCLUSTERED INDEX [IX_Sales_Star_CompanyNumber] ON [dbo].[Sales_Star_Customer]
(
	[CompanyNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [IX_Sales_Star_Customer_CustomerNumberID]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'IX_Sales_Star_Customer_CustomerNumberID')
CREATE NONCLUSTERED INDEX [IX_Sales_Star_Customer_CustomerNumberID] ON [dbo].[Sales_Star_Customer]
(
	[CustomerNumberID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [IX_Sales_Star_Customer_ShipToNumber]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'IX_Sales_Star_Customer_ShipToNumber')
CREATE NONCLUSTERED INDEX [IX_Sales_Star_Customer_ShipToNumber] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoNumber] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [IX_Sales_Star_InvoiceToNumber]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'IX_Sales_Star_InvoiceToNumber')
CREATE NONCLUSTERED INDEX [IX_Sales_Star_InvoiceToNumber] ON [dbo].[Sales_Star_Customer]
(
	[InvoicetoNumber] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [IX_Sales_Star_ParentNumber]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'IX_Sales_Star_ParentNumber')
CREATE NONCLUSTERED INDEX [IX_Sales_Star_ParentNumber] ON [dbo].[Sales_Star_Customer]
(
	[ParentNumber] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [IX_Sales_Star_ShipToNumber]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'IX_Sales_Star_ShipToNumber')
CREATE NONCLUSTERED INDEX [IX_Sales_Star_ShipToNumber] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoNumber] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [IX_Sales_Star_SoldToNumber]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'IX_Sales_Star_SoldToNumber')
CREATE NONCLUSTERED INDEX [IX_Sales_Star_SoldToNumber] ON [dbo].[Sales_Star_Customer]
(
	[SoldtoNumber] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_1]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_1')
CREATE NONCLUSTERED INDEX [missing_index_1] ON [dbo].[Sales_Star_Customer]
(
	[Category03Code] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoName],
	[StopCode]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_101]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_101')
CREATE NONCLUSTERED INDEX [missing_index_101] ON [dbo].[Sales_Star_Customer]
(
	[Category06Code] ASC
)
INCLUDE ( 	[SourceID],
	[ShiptoNumber],
	[Category03Code]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_103]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_103')
CREATE NONCLUSTERED INDEX [missing_index_103] ON [dbo].[Sales_Star_Customer]
(
	[Category06Code] ASC
)
INCLUDE ( 	[Category03Code],
	[Category03]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_105]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_105')
CREATE NONCLUSTERED INDEX [missing_index_105] ON [dbo].[Sales_Star_Customer]
(
	[Category06Code] ASC
)
INCLUDE ( 	[SourceID],
	[ShiptoNumber],
	[Category05Code]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_107]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_107')
CREATE NONCLUSTERED INDEX [missing_index_107] ON [dbo].[Sales_Star_Customer]
(
	[Category06Code] ASC
)
INCLUDE ( 	[Category05Code],
	[Category05]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_109]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_109')
CREATE NONCLUSTERED INDEX [missing_index_109] ON [dbo].[Sales_Star_Customer]
(
	[Category06Code] ASC
)
INCLUDE ( 	[SourceID],
	[ShiptoNumber],
	[Category04Code]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_111]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_111')
CREATE NONCLUSTERED INDEX [missing_index_111] ON [dbo].[Sales_Star_Customer]
(
	[Category06Code] ASC
)
INCLUDE ( 	[Category04Code],
	[Category04]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_115]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_115')
CREATE NONCLUSTERED INDEX [missing_index_115] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoNumber] ASC,
	[StopCode] ASC
)
INCLUDE ( 	[ShiptoName]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [missing_index_117]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_117')
CREATE NONCLUSTERED INDEX [missing_index_117] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_121]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_121')
CREATE NONCLUSTERED INDEX [missing_index_121] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoSearchTypeCode] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoName],
	[DateOfFirstInvoice]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_123]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_123')
CREATE NONCLUSTERED INDEX [missing_index_123] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoSearchType] ASC
)
INCLUDE ( 	[SoldtoNumber],
	[ShiptoNumber],
	[ShiptoSearchTypeCode]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_125]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_125')
CREATE NONCLUSTERED INDEX [missing_index_125] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoSearchTypeCode] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoName],
	[LastInvoiceDate]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_128]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_128')
CREATE NONCLUSTERED INDEX [missing_index_128] ON [dbo].[Sales_Star_Customer]
(
	[Category03Code] ASC
)
INCLUDE ( 	[SourceID],
	[ShiptoNumber],
	[ShiptoName],
	[StopCode]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_144]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_144')
CREATE NONCLUSTERED INDEX [missing_index_144] ON [dbo].[Sales_Star_Customer]
(
	[Category03Code] ASC
)
INCLUDE ( 	[SourceID],
	[ShiptoNumber],
	[StopCode]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_1465]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_1465')
CREATE NONCLUSTERED INDEX [missing_index_1465] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoSearchTypeCode] ASC
)
INCLUDE ( 	[ParentNumber],
	[ParentName],
	[ShiptoNumber],
	[ShiptoName],
	[ShiptoAddressLine01],
	[ShiptoPostalCode],
	[ShiptoCity],
	[ShiptoStateCode],
	[ShiptoState],
	[Category03Code],
	[Category03],
	[Category04Code],
	[Category04],
	[Category05Code],
	[Category05],
	[Category06Code],
	[Category06],
	[Category08Code],
	[Category08],
	[Category21Code],
	[Category21],
	[Category25Code],
	[Category25],
	[Category27Code],
	[Category27],
	[Category28Code],
	[Category28]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_147]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_147')
CREATE NONCLUSTERED INDEX [missing_index_147] ON [dbo].[Sales_Star_Customer]
(
	[Category08Code] ASC
)
INCLUDE ( 	[CustomerNumberID],
	[SourceID],
	[ShiptoNumber],
	[Category08]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_1473]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_1473')
CREATE NONCLUSTERED INDEX [missing_index_1473] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoSearchTypeCode] ASC,
	[Category06Code] ASC
)
INCLUDE ( 	[ParentNumber],
	[ParentName],
	[ShiptoNumber],
	[ShiptoName],
	[ShiptoAddressLine01],
	[ShiptoPostalCode],
	[ShiptoCity],
	[ShiptoStateCode],
	[ShiptoState],
	[Category03Code],
	[Category03],
	[Category04Code],
	[Category04],
	[Category05Code],
	[Category05],
	[Category06],
	[Category08Code],
	[Category08],
	[Category21Code],
	[Category21],
	[Category25Code],
	[Category25],
	[Category27Code],
	[Category27],
	[Category28Code],
	[Category28]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_152]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_152')
CREATE NONCLUSTERED INDEX [missing_index_152] ON [dbo].[Sales_Star_Customer]
(
	[StopCode] ASC,
	[Category03Code] ASC
)
INCLUDE ( 	[SourceID],
	[ShiptoNumber],
	[ShiptoName]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_157]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_157')
CREATE NONCLUSTERED INDEX [missing_index_157] ON [dbo].[Sales_Star_Customer]
(
	[Category03Code] ASC,
	[ShiptoSearchTypeCode] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoName],
	[LastInvoiceDate]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_159]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_159')
CREATE NONCLUSTERED INDEX [missing_index_159] ON [dbo].[Sales_Star_Customer]
(
	[Category05Code] ASC,
	[ShiptoSearchTypeCode] ASC,
	[Category03Code] ASC
)
INCLUDE ( 	[CustomerNumberID],
	[SourceID],
	[ShiptoNumber],
	[ShiptoName]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_170]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_170')
CREATE NONCLUSTERED INDEX [missing_index_170] ON [dbo].[Sales_Star_Customer]
(
	[StopCode] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoName]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_177]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_177')
CREATE NONCLUSTERED INDEX [missing_index_177] ON [dbo].[Sales_Star_Customer]
(
	[Category04Code] ASC,
	[Category05Code] ASC,
	[Category06Code] ASC
)
INCLUDE ( 	[CustomerNumberID],
	[SourceID],
	[ShiptoNumber],
	[Category03Code],
	[Category03]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_179]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_179')
CREATE NONCLUSTERED INDEX [missing_index_179] ON [dbo].[Sales_Star_Customer]
(
	[Category05Code] ASC
)
INCLUDE ( 	[Category04Code],
	[Category04]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_180]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_180')
CREATE NONCLUSTERED INDEX [missing_index_180] ON [dbo].[Sales_Star_Customer]
(
	[Category04Code] ASC,
	[Category05Code] ASC,
	[Category06Code] ASC
)
INCLUDE ( 	[CustomerNumberID],
	[SourceID],
	[ShiptoNumber],
	[Category04]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_19]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_19')
CREATE NONCLUSTERED INDEX [missing_index_19] ON [dbo].[Sales_Star_Customer]
(
	[Category03Code] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoName],
	[LastInvoiceDate]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_202]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_202')
CREATE NONCLUSTERED INDEX [missing_index_202] ON [dbo].[Sales_Star_Customer]
(
	[Category04Code] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoSearchTypeCode],
	[HOLDORDERSCODEDescription],
	[DateOfFirstInvoice],
	[LastInvoiceDate]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_204]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_204')
CREATE NONCLUSTERED INDEX [missing_index_204] ON [dbo].[Sales_Star_Customer]
(
	[Category04Code] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoSearchTypeCode],
	[StopCode],
	[DateOfFirstInvoice],
	[LastInvoiceDate]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_206]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_206')
CREATE NONCLUSTERED INDEX [missing_index_206] ON [dbo].[Sales_Star_Customer]
(
	[Category04Code] ASC,
	[ShiptoSearchTypeCode] ASC
)
INCLUDE ( 	[SourceID],
	[ShiptoNumber],
	[ShiptoName],
	[StopCode],
	[Category03Code]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_208]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_208')
CREATE NONCLUSTERED INDEX [missing_index_208] ON [dbo].[Sales_Star_Customer]
(
	[Category03Code] ASC
)
INCLUDE ( 	[Category03]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_212]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_212')
CREATE NONCLUSTERED INDEX [missing_index_212] ON [dbo].[Sales_Star_Customer]
(
	[Category09Code] ASC,
	[ShiptoSearchTypeCode] ASC
)
INCLUDE ( 	[ParentNumber],
	[ParentName],
	[ShiptoNumber],
	[ShiptoName],
	[ShiptoAddressLine01],
	[ShiptoPostalCode],
	[ShiptoCity],
	[ShiptoStateCode],
	[ShiptoState],
	[StopCode],
	[Category03Code],
	[Category03],
	[Category04Code],
	[Category04],
	[Category05Code],
	[Category05],
	[Category06Code],
	[Category06],
	[Category08Code],
	[Category08],
	[Category21Code],
	[Category21],
	[Category25Code],
	[Category25],
	[Category27Code],
	[Category27],
	[Category28Code],
	[Category28]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_214]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_214')
CREATE NONCLUSTERED INDEX [missing_index_214] ON [dbo].[Sales_Star_Customer]
(
	[Category04Code] ASC,
	[ShiptoSearchTypeCode] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoName],
	[Category03Code],
	[LastInvoiceDate]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_216]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_216')
CREATE NONCLUSTERED INDEX [missing_index_216] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoSearchTypeCode] ASC,
	[Category03Code] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoName],
	[LastInvoiceDate]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_225]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_225')
CREATE NONCLUSTERED INDEX [missing_index_225] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoSearchTypeCode] ASC,
	[Category03Code] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoName],
	[ShiptoAddressLine01],
	[ShiptoPostalCode],
	[ShiptoCity],
	[ShiptoStateCode],
	[ShiptoState],
	[ShiptoSearchType],
	[StopCode],
	[Category03]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_242]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_242')
CREATE NONCLUSTERED INDEX [missing_index_242] ON [dbo].[Sales_Star_Customer]
(
	[Category04Code] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoSearchTypeCode],
	[DateOfFirstInvoice],
	[LastInvoiceDate]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_272]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_272')
CREATE NONCLUSTERED INDEX [missing_index_272] ON [dbo].[Sales_Star_Customer]
(
	[Category04Code] ASC
)
INCLUDE ( 	[SourceID],
	[ShiptoNumber],
	[ShiptoName],
	[StopCode],
	[Category03Code]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_276]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_276')
CREATE NONCLUSTERED INDEX [missing_index_276] ON [dbo].[Sales_Star_Customer]
(
	[StopCode] ASC
)
INCLUDE ( 	[SourceID],
	[ShiptoNumber]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_32]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_32')
CREATE NONCLUSTERED INDEX [missing_index_32] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoSearchTypeCode] ASC
)
INCLUDE ( 	[CustomerNumberID],
	[SourceID],
	[ParentNumber],
	[ShiptoNumber],
	[ShiptoAddressLine01],
	[ShiptoAddressLine02],
	[ShiptoPostalCode],
	[ShiptoCity],
	[ShiptoStateCode],
	[Category03Code],
	[Category08Code]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_357]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_357')
CREATE NONCLUSTERED INDEX [missing_index_357] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoSearchTypeCode] ASC
)
INCLUDE ( 	[ParentNumber],
	[ParentName],
	[ShiptoNumber],
	[ShiptoName],
	[ShiptoAddressLine01],
	[ShiptoPostalCode],
	[ShiptoCity],
	[ShiptoStateCode],
	[ShiptoState],
	[ShiptoSearchType],
	[Category03Code],
	[Category03],
	[Category04Code],
	[Category04],
	[Category05Code],
	[Category05],
	[Category06Code],
	[Category06],
	[Category08Code],
	[Category08],
	[Category25Code],
	[Category25]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_493]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_493')
CREATE NONCLUSTERED INDEX [missing_index_493] ON [dbo].[Sales_Star_Customer]
(
	[Category06Code] ASC,
	[ShiptoSearchTypeCode] ASC
)
INCLUDE ( 	[SourceID],
	[ShiptoNumber],
	[ShiptoName],
	[StopCode],
	[Category03Code]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_517]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_517')
CREATE NONCLUSTERED INDEX [missing_index_517] ON [dbo].[Sales_Star_Customer]
(
	[Category05Code] ASC,
	[Category06Code] ASC,
	[ShiptoSearchTypeCode] ASC,
	[Category03Code] ASC
)
INCLUDE ( 	[SourceID],
	[ShiptoNumber],
	[ShiptoName],
	[StopCode]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_519]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_519')
CREATE NONCLUSTERED INDEX [missing_index_519] ON [dbo].[Sales_Star_Customer]
(
	[Category05Code] ASC,
	[Category06Code] ASC,
	[ShiptoSearchTypeCode] ASC,
	[Category03Code] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoName],
	[LastInvoiceDate]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_534]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_534')
CREATE NONCLUSTERED INDEX [missing_index_534] ON [dbo].[Sales_Star_Customer]
(
	[Category05Code] ASC,
	[ShiptoSearchTypeCode] ASC,
	[Category03Code] ASC
)
INCLUDE ( 	[SourceID],
	[ShiptoNumber],
	[ShiptoName],
	[StopCode]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_6]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_6')
CREATE NONCLUSTERED INDEX [missing_index_6] ON [dbo].[Sales_Star_Customer]
(
	[Category03Code] ASC
)
INCLUDE ( 	[SoldtoNumber],
	[SoldtoName],
	[StopCode]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_648]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_648')
CREATE NONCLUSTERED INDEX [missing_index_648] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoSearchTypeCode] ASC
)
INCLUDE ( 	[InvoicetoNumber],
	[InvoicetoName],
	[SoldtoNumber],
	[SoldtoName],
	[ShiptoNumber],
	[ShiptoName]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_652]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_652')
CREATE NONCLUSTERED INDEX [missing_index_652] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoSearchTypeCode] ASC
)
INCLUDE ( 	[CustomerNumberID],
	[SourceID],
	[ShiptoNumber],
	[ShiptoName]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_653]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_653')
CREATE NONCLUSTERED INDEX [missing_index_653] ON [dbo].[Sales_Star_Customer]
(
	[Category04Code] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoName],
	[Category03Code],
	[LastInvoiceDate]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_7]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_7')
CREATE NONCLUSTERED INDEX [missing_index_7] ON [dbo].[Sales_Star_Customer]
(
	[Category08Code] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoName],
	[DateOfFirstInvoice]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_8]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_8')
CREATE NONCLUSTERED INDEX [missing_index_8] ON [dbo].[Sales_Star_Customer]
(
	[Category03Code] ASC
)
INCLUDE ( 	[StopCode]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_83]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_83')
CREATE NONCLUSTERED INDEX [missing_index_83] ON [dbo].[Sales_Star_Customer]
(
	[Category06Code] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoName],
	[StopCode]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_87]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_87')
CREATE NONCLUSTERED INDEX [missing_index_87] ON [dbo].[Sales_Star_Customer]
(
	[Category06Code] ASC
)
INCLUDE ( 	[CustomerNumberID],
	[SourceID],
	[ShiptoNumber],
	[Category06]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_908]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_908')
CREATE NONCLUSTERED INDEX [missing_index_908] ON [dbo].[Sales_Star_Customer]
(
	[ShiptoSearchTypeCode] ASC
)
INCLUDE ( 	[ParentNumber],
	[ParentName],
	[ShiptoNumber],
	[ShiptoName],
	[ShiptoAddressLine01],
	[ShiptoPostalCode],
	[ShiptoCity],
	[ShiptoStateCode],
	[ShiptoState],
	[StopCode],
	[Category03Code],
	[Category03],
	[Category04Code],
	[Category04],
	[Category05Code],
	[Category05],
	[Category06Code],
	[Category06],
	[Category08Code],
	[Category08],
	[Category21Code],
	[Category21],
	[Category25Code],
	[Category25],
	[Category27Code],
	[Category27],
	[Category28Code],
	[Category28]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_YCHOI1]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'missing_index_YCHOI1')
CREATE NONCLUSTERED INDEX [missing_index_YCHOI1] ON [dbo].[Sales_Star_Customer]
(
	[Category05Code] ASC,
	[ShiptoSearchTypeCode] ASC,
	[Category03Code] ASC
)
INCLUDE ( 	[ShiptoNumber],
	[ShiptoName],
	[LastInvoiceDate]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [NET SALES BY  Levels-FOR AOP PURPOSES_DTA_K1_K60_K2_K47]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Star_Customer]') AND name = N'NET SALES BY  Levels-FOR AOP PURPOSES_DTA_K1_K60_K2_K47')
CREATE NONCLUSTERED INDEX [NET SALES BY  Levels-FOR AOP PURPOSES_DTA_K1_K60_K2_K47] ON [dbo].[Sales_Star_Customer]
(
	[CustomerNumberID] ASC,
	[ShiptoSearchTypeCode] ASC,
	[SourceID] ASC,
	[ShiptoNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Account_AIDID]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Account]') AND name = N'IX_Account_AIDID')
CREATE NONCLUSTERED INDEX [IX_Account_AIDID] ON [dbo].[Star_Account]
(
	[AIDID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [IX_Account_BU]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Account]') AND name = N'IX_Account_BU')
CREATE NONCLUSTERED INDEX [IX_Account_BU] ON [dbo].[Star_Account]
(
	[Account] ASC,
	[BusinessUnitCode] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_1]    Script Date: 5/30/13 12:57:36 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Account]') AND name = N'missing_index_1')
CREATE NONCLUSTERED INDEX [missing_index_1] ON [dbo].[Star_Account]
(
	[BusinessUnitCode] ASC
)
INCLUDE ( 	[SourceID],
	[Account],
	[AccountDesc],
	[AccountLevelOfDetail]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_204]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Account]') AND name = N'missing_index_204')
CREATE NONCLUSTERED INDEX [missing_index_204] ON [dbo].[Star_Account]
(
	[Category12Code] ASC
)
INCLUDE ( 	[AIDID]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_264]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Account]') AND name = N'missing_index_264')
CREATE NONCLUSTERED INDEX [missing_index_264] ON [dbo].[Star_Account]
(
	[Category17Code] ASC
)
INCLUDE ( 	[Category17],
	[Category17Desc2]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_44]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Account]') AND name = N'missing_index_44')
CREATE NONCLUSTERED INDEX [missing_index_44] ON [dbo].[Star_Account]
(
	[Category13Code] ASC
)
INCLUDE ( 	[AIDID],
	[Category13],
	[Category14Code],
	[Category14]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_53]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Account]') AND name = N'missing_index_53')
CREATE NONCLUSTERED INDEX [missing_index_53] ON [dbo].[Star_Account]
(
	[Category13Code] ASC
)
INCLUDE ( 	[AIDID],
	[Account],
	[AccountDesc],
	[Category13],
	[Category14Code],
	[Category14]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_66]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Account]') AND name = N'missing_index_66')
CREATE NONCLUSTERED INDEX [missing_index_66] ON [dbo].[Star_Account]
(
	[Category13Code] ASC
)
INCLUDE ( 	[AIDID]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_89]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Account]') AND name = N'missing_index_89')
CREATE NONCLUSTERED INDEX [missing_index_89] ON [dbo].[Star_Account]
(
	[Category13Code] ASC
)
INCLUDE ( 	[AIDID],
	[Account],
	[AccountDesc],
	[AccountLevelOfDetail],
	[Category13],
	[Category14Code],
	[Category14]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [IX_Account_Model_AccountID]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Account_Model]') AND name = N'IX_Account_Model_AccountID')
CREATE NONCLUSTERED INDEX [IX_Account_Model_AccountID] ON [dbo].[Star_Account_Model]
(
	[AccountID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
GO
/****** Object:  Index [IX_AddressBook_AddressNumberID]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_AddressBook]') AND name = N'IX_AddressBook_AddressNumberID')
CREATE NONCLUSTERED INDEX [IX_AddressBook_AddressNumberID] ON [dbo].[Star_AddressBook]
(
	[AddressNumberID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [index_Star_BusinessUnit_K1_K49_K45_K9_46_50]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_BusinessUnit]') AND name = N'index_Star_BusinessUnit_K1_K49_K45_K9_46_50')
CREATE NONCLUSTERED INDEX [index_Star_BusinessUnit_K1_K49_K45_K9_46_50] ON [dbo].[Star_BusinessUnit]
(
	[BusinessUnitID] ASC,
	[Category20Code] ASC,
	[Category18Code] ASC,
	[CompanyNumber] ASC
)
INCLUDE ( 	[Category18],
	[Category20]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [IX_BusinessUnit_BusinessUnitID]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_BusinessUnit]') AND name = N'IX_BusinessUnit_BusinessUnitID')
CREATE NONCLUSTERED INDEX [IX_BusinessUnit_BusinessUnitID] ON [dbo].[Star_BusinessUnit]
(
	[BusinessUnitID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_196]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_BusinessUnit]') AND name = N'missing_index_196')
CREATE NONCLUSTERED INDEX [missing_index_196] ON [dbo].[Star_BusinessUnit]
(
	[BusinessUnitID] ASC
)
INCLUDE ( 	[BusinessUnitCode],
	[BusinessUnit],
	[AddressNumber]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_386]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_BusinessUnit]') AND name = N'missing_index_386')
CREATE NONCLUSTERED INDEX [missing_index_386] ON [dbo].[Star_BusinessUnit]
(
	[Category01Code] ASC
)
INCLUDE ( 	[BusinessUnitID]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_463]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_BusinessUnit]') AND name = N'missing_index_463')
CREATE NONCLUSTERED INDEX [missing_index_463] ON [dbo].[Star_BusinessUnit]
(
	[Type] ASC
)
INCLUDE ( 	[BusinessUnitID]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [IX_Company_CompanyNumberID]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Company]') AND name = N'IX_Company_CompanyNumberID')
CREATE NONCLUSTERED INDEX [IX_Company_CompanyNumberID] ON [dbo].[Star_Company]
(
	[CompanyNumberID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
GO
/****** Object:  Index [IX_Cost_CostID]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Cost]') AND name = N'IX_Cost_CostID')
CREATE NONCLUSTERED INDEX [IX_Cost_CostID] ON [dbo].[Star_Cost]
(
	[CostID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [missing_index_269]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Cost]') AND name = N'missing_index_269')
CREATE NONCLUSTERED INDEX [missing_index_269] ON [dbo].[Star_Cost]
(
	[ItemNumber02] ASC,
	[CostMethodCode] ASC
)
INCLUDE ( 	[BusinessUnitCode],
	[UnitCost],
	[DateUpdated]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [_dta_index_Star_Dates_11_1093578934__K1_K57]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Dates]') AND name = N'_dta_index_Star_Dates_11_1093578934__K1_K57')
CREATE NONCLUSTERED INDEX [_dta_index_Star_Dates_11_1093578934__K1_K57] ON [dbo].[Star_Dates]
(
	[Dates] ASC,
	[CompanyDateID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Dates]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Dates]') AND name = N'IX_Dates')
CREATE NONCLUSTERED INDEX [IX_Dates] ON [dbo].[Star_Dates]
(
	[Dates] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_778]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Dates]') AND name = N'missing_index_778')
CREATE NONCLUSTERED INDEX [missing_index_778] ON [dbo].[Star_Dates]
(
	[FiscalMonth] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [R&G EX Price and LBS-Foodservice_DTA_041912_K1_K57_K14]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Dates]') AND name = N'R&G EX Price and LBS-Foodservice_DTA_041912_K1_K57_K14')
CREATE NONCLUSTERED INDEX [R&G EX Price and LBS-Foodservice_DTA_041912_K1_K57_K14] ON [dbo].[Star_Dates]
(
	[Dates] ASC,
	[CompanyDateID] ASC,
	[FiscalMonth] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [index_Star_Employee_K1_4_6]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Employee]') AND name = N'index_Star_Employee_K1_4_6')
CREATE NONCLUSTERED INDEX [index_Star_Employee_K1_4_6] ON [dbo].[Star_Employee]
(
	[EmployeeNumberID] ASC
)
INCLUDE ( 	[EmployeeNumber],
	[EmployeeName]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Employee_EmployeeNumberID]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Employee]') AND name = N'IX_Employee_EmployeeNumberID')
CREATE NONCLUSTERED INDEX [IX_Employee_EmployeeNumberID] ON [dbo].[Star_Employee]
(
	[EmployeeNumberID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
GO
/****** Object:  Index [IX_FiscalYear_FiscalYearID]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_FiscalYear]') AND name = N'IX_FiscalYear_FiscalYearID')
CREATE NONCLUSTERED INDEX [IX_FiscalYear_FiscalYearID] ON [dbo].[Star_FiscalYear]
(
	[FiscalYearID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
GO
/****** Object:  Index [IX_Item_ItemNumberID]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Item]') AND name = N'IX_Item_ItemNumberID')
CREATE NONCLUSTERED INDEX [IX_Item_ItemNumberID] ON [dbo].[Star_Item]
(
	[ItemNumberID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [missing_index_119]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Item]') AND name = N'missing_index_119')
CREATE NONCLUSTERED INDEX [missing_index_119] ON [dbo].[Star_Item]
(
	[SalesCategory01Code] ASC
)
INCLUDE ( 	[ItemNumberID],
	[SourceID],
	[Source],
	[ItemNumber],
	[ItemNumber02],
	[ItemNumber03],
	[Description01],
	[Description02],
	[SalesCategory01],
	[SalesCategory02Code],
	[SalesCategory02],
	[SalesCategory03Code],
	[SalesCategory03],
	[SalesCategory04Code],
	[SalesCategory04],
	[SalesCategory05Code],
	[SalesCategory05],
	[SalesCategory06Code],
	[SalesCategory06],
	[SalesCategory07Code],
	[SalesCategory07],
	[SalesCategory08Code],
	[SalesCategory08],
	[SalesCategory09Code],
	[SalesCategory09],
	[SalesCategory10Code],
	[SalesCategory10],
	[PurchasingCategory01Code],
	[PurchasingCategory01],
	[PurchasingCategory02Code],
	[PurchasingCategory02],
	[PurchasingCategory03Code],
	[PurchasingCategory03],
	[PurchasingCategory04Code],
	[PurchasingCategory04],
	[PurchasingCategory05Code],
	[PurchasingCategory05],
	[PurchasingCategory06Code],
	[PurchasingCategory06],
	[PurchasingCategory07Code],
	[PurchasingCategory07],
	[PurchasingCategory08Code],
	[PurchasingCategory08],
	[PurchasingCategory09Code],
	[PurchasingCategory09],
	[PurchasingCategory10Code],
	[PurchasingCategory10],
	[ProductGroupCode],
	[ProductGroup],
	[ItemPriceGroupCode],
	[ItemPriceGroup],
	[StockingTypeCode],
	[StockingType],
	[InsertIndicator],
	[InsertDate],
	[ChangeIndicator],
	[ChangeDate],
	[DeleteIndicator],
	[DeleteDate],
	[PurgeDate]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [missing_index_172]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Item]') AND name = N'missing_index_172')
CREATE NONCLUSTERED INDEX [missing_index_172] ON [dbo].[Star_Item]
(
	[SalesCategory03Code] ASC
)
INCLUDE ( 	[ItemNumberID],
	[SourceID],
	[ItemNumber],
	[ItemNumber02]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [missing_index_433]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Item]') AND name = N'missing_index_433')
CREATE NONCLUSTERED INDEX [missing_index_433] ON [dbo].[Star_Item]
(
	[Description01] ASC
)
INCLUDE ( 	[ItemNumberID],
	[SourceID],
	[ItemNumber02]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [IX_IB_Addressnumber]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_ItemBranch]') AND name = N'IX_IB_Addressnumber')
CREATE NONCLUSTERED INDEX [IX_IB_Addressnumber] ON [dbo].[Star_ItemBranch]
(
	[AddressNumber] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [IX_ItemBranch_ItemBranchID]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_ItemBranch]') AND name = N'IX_ItemBranch_ItemBranchID')
CREATE NONCLUSTERED INDEX [IX_ItemBranch_ItemBranchID] ON [dbo].[Star_ItemBranch]
(
	[ItemBranchID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [missing_index_257]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_ItemBranch]') AND name = N'missing_index_257')
CREATE NONCLUSTERED INDEX [missing_index_257] ON [dbo].[Star_ItemBranch]
(
	[SalesCategory01Code] ASC
)
INCLUDE ( 	[ItemNumber],
	[BusinessUnitCode],
	[SafetyStock]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [missing_index_660]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_ItemBranch]') AND name = N'missing_index_660')
CREATE NONCLUSTERED INDEX [missing_index_660] ON [dbo].[Star_ItemBranch]
(
	[SourceID] ASC,
	[BusinessUnitCode] ASC
)
INCLUDE ( 	[ItemNumber],
	[AddressNumber]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [IX_PaymentTerms_PaymentTermsID]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_PaymentTerms]') AND name = N'IX_PaymentTerms_PaymentTermsID')
CREATE NONCLUSTERED INDEX [IX_PaymentTerms_PaymentTermsID] ON [dbo].[Star_PaymentTerms]
(
	[PaymentTermID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
GO
/****** Object:  Index [IX_Price_PriceID]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Price]') AND name = N'IX_Price_PriceID')
CREATE NONCLUSTERED INDEX [IX_Price_PriceID] ON [dbo].[Star_Price]
(
	[PriceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
GO
/****** Object:  Index [IX_SourceID_ParentNum]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Supplier]') AND name = N'IX_SourceID_ParentNum')
CREATE NONCLUSTERED INDEX [IX_SourceID_ParentNum] ON [dbo].[Star_Supplier]
(
	[SourceID] ASC,
	[ParentNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [IX_Supplier_SupplierNumberID]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Supplier]') AND name = N'IX_Supplier_SupplierNumberID')
CREATE NONCLUSTERED INDEX [IX_Supplier_SupplierNumberID] ON [dbo].[Star_Supplier]
(
	[SupplierNumberID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
/****** Object:  Index [missing_index_422]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_Supplier]') AND name = N'missing_index_422')
CREATE NONCLUSTERED INDEX [missing_index_422] ON [dbo].[Star_Supplier]
(
	[SearchTypeCode] ASC
)
INCLUDE ( 	[SupplierNumberID],
	[SupplierNumber],
	[SupplierName],
	[PaymentTermsAP],
	[PaymentTerms],
	[SearchType]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [_dta_index_Star_UOMConversionFactors_11_1413580074__K5_K4_K6_2_3_8]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_UOMConversionFactors]') AND name = N'_dta_index_Star_UOMConversionFactors_11_1413580074__K5_K4_K6_2_3_8')
CREATE NONCLUSTERED INDEX [_dta_index_Star_UOMConversionFactors_11_1413580074__K5_K4_K6_2_3_8] ON [dbo].[Star_UOMConversionFactors]
(
	[UnitOfMeasure] ASC,
	[ItemNumber] ASC,
	[RelatedUnitOfMeasure] ASC
)
INCLUDE ( 	[SourceID],
	[BusinessUnitCode],
	[ConversionFactor]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [IX_index_Star_UOMConversionFactors_ychoi_040312]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_UOMConversionFactors]') AND name = N'IX_index_Star_UOMConversionFactors_ychoi_040312')
CREATE NONCLUSTERED INDEX [IX_index_Star_UOMConversionFactors_ychoi_040312] ON [dbo].[Star_UOMConversionFactors]
(
	[UnitOfMeasure] ASC,
	[ItemNumber] ASC,
	[RelatedUnitOfMeasure] ASC,
	[BusinessUnitCode] ASC,
	[SourceID] ASC
)
INCLUDE ( 	[ConversionFactor]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_303]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_UOMConversionFactors]') AND name = N'missing_index_303')
CREATE NONCLUSTERED INDEX [missing_index_303] ON [dbo].[Star_UOMConversionFactors]
(
	[RelatedUnitOfMeasure] ASC
)
INCLUDE ( 	[ItemNumber],
	[UnitOfMeasure],
	[ConversionFactor]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [missing_index_6]    Script Date: 5/30/13 12:57:37 PM ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Star_UOMConversionFactors]') AND name = N'missing_index_6')
CREATE NONCLUSTERED INDEX [missing_index_6] ON [dbo].[Star_UOMConversionFactors]
(
	[ItemNumber] ASC,
	[UnitOfMeasure] ASC,
	[RelatedUnitOfMeasure] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
GO
